﻿#include "maco.h"
#include "ui_maco.h"
intListener recfl;
QString recvvalue;
QString txtype="0";
extern intListener doorStatus;
QSize CustomTabStyle::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
{
    QSize s=QProxyStyle::sizeFromContents(type,option,size,widget);
    if(type==QStyle::CT_TabBarTab){
        s.transposed();
        s.rwidth()=168;
        s.rheight()=50;
    }
    return s;
}
void CustomTabStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    if(element==CE_TabBarTabLabel){
        if(const QStyleOptionTab *tab=qstyleoption_cast<const QStyleOptionTab *>(option)){
            QRect allRect=tab->rect;
            if(tab->state&QStyle::State_Selected){
                painter->save();
                painter->setPen(0x89cfff);
                painter->setBrush(QBrush(0x89cfff));
                painter->drawRect(allRect.adjusted(6,6,-6,-6));
                painter->restore();
            }
            QTextOption option;
            option.setAlignment(Qt::AlignCenter);
            if(tab->state&QStyle::State_Selected){
                painter->setPen(0xf8fcff);
            }else{
                painter->setPen(0x000001);
            }
            painter->drawText(allRect,tab->text,option);
            return ;
        }
    }
    if(element==CE_TabBarTab){
        QProxyStyle::drawControl(element,option,painter,widget);
    }
}
maco::maco(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::maco)
{
    ui->setupUi(this);
    pcmap.insert("A",0);
    pcmap.insert("B",1);
    pcmap.insert("C",2);
    pcmap.insert("D",3);
    pcmap.insert("E",4);
    pcmap.insert("F",5);
    qtwh1 = new qtwh();
    ui->tabWidget->tabBar()->setStyle(new CustomTabStyle);
    ui->tabWidget_2->tabBar()->setStyle(new CustomTabStyle);
    ui->tabWidget_3->tabBar()->setStyle(new CustomTabStyle);
    tcpClient=TcpClient::getInstance();
    recfl.set(0);
    adtw();
    ui->ad_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->ad_tw->verticalHeader()->setDefaultSectionSize(30);
    ui->ad_tw->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    sptw();
    ui->sp_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->sp_tw->verticalHeader()->setDefaultSectionSize(30);
    ui->sp_tw->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    xztw();
    ui->xz_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->xz_tw->verticalHeader()->setDefaultSectionSize(30);
    ui->xz_tw->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    sjwtab();
    ui->sjwtab_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->sjwtab_tw->verticalHeader()->setDefaultSectionSize(30);
    ui->sjwtab_tw->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    kbtw();
    ui->kb_tw->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->kb_tw->verticalHeader()->setDefaultSectionSize(30);
    ui->kb_tw->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    pctab();
    ui->pc_tab->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->pc_tab->verticalHeader()->setDefaultSectionSize(30);
    ui->pc_tab->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    bjtab();
    for(int i=0;i<ui->bj_tab->columnCount();i++){
        ui->bj_tab->setColumnWidth(i, 70);
    }
    ui->bj_tab->verticalHeader()->setDefaultSectionSize(30);
    ui->bj_tab->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    QStringList serialNamePort;
    serialPort = new QSerialPort(this);
    foreach (const QSerialPortInfo &info,QSerialPortInfo::availablePorts()) {
        serialNamePort<<info.portName(); //串口获取
    }

    connect(&recfl, &intListener::valueChanged, this,&maco::readyRead_Slot);
    connect(qtwh1->ui->sbo_bt,SIGNAL(clicked()),this,SLOT(sbo_Slot()));
    connect(qtwh1->ui->sbc_bt,SIGNAL(clicked()),this,SLOT(sbc_Slot()));
    connect(qtwh1->ui->fso_bt,SIGNAL(clicked()),this,SLOT(fso_Slot()));
    connect(qtwh1->ui->fsc_bt,SIGNAL(clicked()),this,SLOT(fsc_Slot()));
    connect(qtwh1->ui->qd_bt,SIGNAL(clicked()),this,SLOT(ckcon_Slot()));
    connect(serialPort,SIGNAL(readyRead()),this,SLOT(serialPortRead_Slot()));// 串口读取
    ui->rgwd_bt2->setEnabled(false);
    ui->dqg_bt->setEnabled(false);
    ui->xzrst_bt->setEnabled(false);
    ui->sprst_bt->setEnabled(false);
    ui->cmg_bt->setEnabled(false);
    ui->rktzrz_bt->setEnabled(false);
    ui->jzs_bt->setEnabled(false);
    ui->sjws_bt->setEnabled(false);
    connect(&doorStatus, &intListener::valueChanged,this,&maco::doorStatusChanged,Qt::QueuedConnection);
#ifdef Q_OS_ANDROID
    int fontId = QFontDatabase::addApplicationFont(":/FontStyle/AlibabaPuHuiTi-3-55-Regular.ttf");
    if (fontId != -1) {
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if (!fontFamilies.isEmpty()) {
            QString familyName = fontFamilies.first();
            QFont font(familyName, 20); // 创建一个QFont对象，设置字体名称和默认大小

            // 使用setFont方法设置字体，传入QFont对象
            ui->top_bt1->setFont(font);
            ui->top_bt2->setFont(font);
            ui->top_bt3->setFont(font);
            ui->type3_lb->setFont(font);
            ui->label_3->setFont(font);
            ui->rgwd_le->setFont(font);
            ui->rgwd_bt1->setFont(font);
            ui->rgwd_bt2->setFont(font);
            ui->rgwd_bt3->setFont(font);
            ui->tabWidget_2->setFont(font);
            ui->tabWidget_3->setFont(font);
            ui->dkg_cb->setFont(font);
            ui->dqk_bt->setFont(font);
            ui->dqg_bt->setFont(font);
            ui->label_4->setFont(font);
            ui->ygtd_cb->setFont(font);
            ui->label_5->setFont(font);
            ui->adti_le->setFont(font);
            ui->label_6->setFont(font);
            ui->adtime_le->setFont(font);
            ui->ad1time_bt->setFont(font);
            ui->adtimes_bt->setFont(font);
            ui->adyd_bt->setFont(font);
            ui->ad_tw->setFont(font);
            ui->spr_bt->setFont(font);
            ui->spw_bt->setFont(font);
            ui->spy_bt->setFont(font);
            ui->spf_bt->setFont(font);
            ui->sp_tw->setFont(font);
            ui->label_8->setFont(font);
            ui->sps_cb->setFont(font);
            ui->label_9->setFont(font);
            ui->spt_le->setFont(font);
            ui->sprte_bt->setFont(font);
            ui->sprst_bt->setFont(font);
            ui->xzr_bt->setFont(font);
            ui->xzw_bt->setFont(font);
            ui->xzy_bt->setFont(font);
            ui->xzf_bt->setFont(font);
            ui->xz_tw->setFont(font);
            ui->label_12->setFont(font);
            ui->xzs_cb->setFont(font);
            ui->label_13->setFont(font);
            ui->xzt_le->setFont(font);
            ui->xzrte_bt->setFont(font);
            ui->xzrst_bt->setFont(font);
            ui->label_14->setFont(font);
            ui->gqt_cb->setFont(font);
            ui->label_15->setFont(font);
            ui->qgv_le->setFont(font);
            ui->gqr_bt->setFont(font);
            ui->gqw_bt->setFont(font);
            ui->label_23->setFont(font);
            ui->label_24->setFont(font);
            ui->label_25->setFont(font);
            ui->label_26->setFont(font);
            ui->lineEdit->setFont(font);
            ui->label_27->setFont(font);
            ui->label_33->setFont(font);
            ui->label_34->setFont(font);
            ui->label_35->setFont(font);
            ui->lineEdit_6->setFont(font);
            ui->lineEdit_2->setFont(font);
            ui->lineEdit_3->setFont(font);
            ui->lineEdit_4->setFont(font);
            ui->lineEdit_5->setFont(font);
            ui->gqr_bt_2->setFont(font);
            ui->gqw_bt_2->setFont(font);
            ui->label_2->setFont(font);
            ui->A_bt->setFont(font);
            ui->B_bt->setFont(font);
            ui->C_bt->setFont(font);
            ui->D_bt->setFont(font);
            ui->E_bt->setFont(font);
            ui->F_bt->setFont(font);
            ui->label_22->setFont(font);
            ui->pc_cb->setFont(font);
            ui->pc_tab->setFont(font);
            ui->bjbc_bt->setFont(font);
            ui->bjdqbt->setFont(font);
            ui->bjdr_bt->setFont(font);
            ui->bot_bt1->setFont(font);
            ui->bot_bt2->setFont(font);
            ui->bot_bt3->setFont(font);
            ui->bot_bt4->setFont(font);
            ui->bot_bt2_2->setFont(font);
            ui->bjdc_bt->setFont(font);
            ui->bj_tab->setFont(font);
            ui->label_16->setFont(font);
            ui->pzv_le->setFont(font);
            ui->cmk_bt->setFont(font);
            ui->cmg_bt->setFont(font);
            ui->label_18->setFont(font);
            ui->hclx_cb->setFont(font);
            ui->label_19->setFont(font);
            ui->bs_le->setFont(font);
            ui->djss_bt->setFont(font);
            ui->djfw_bt->setFont(font);
//            ui->hczdjz_bt->setFont(font);
            ui->label_20->setFont(font);
            ui->rgrz_cb->setFont(font);
            ui->label_21->setFont(font);
            ui->rgrzt_bt->setFont(font);
            ui->rkrzcs_bt->setFont(font);
            ui->rktzrz_bt->setFont(font);
            ui->sjwr_bt->setFont(font);
            ui->sjww_bt->setFont(font);
            ui->sjwtab_tw->setFont(font);
            ui->label_29->setFont(font);
            ui->sw_le->setFont(font);
            ui->sw_bt->setFont(font);
            ui->label_30->setFont(font);
            ui->jw_le->setFont(font);
            ui->jw_bt->setFont(font);
            ui->sjws_bt->setFont(font);
            ui->label_31->setFont(font);
            ui->jr_le->setFont(font);
            ui->jr_bt->setFont(font);
            ui->label_32->setFont(font);
            ui->zl_le->setFont(font);
            ui->zl_bt->setFont(font);
            ui->jzs_bt->setFont(font);
            ui->kbr_bt->setFont(font);
            ui->kbw_bt->setFont(font);
            ui->kb_tw->setFont(font);
            ui->label_36->setFont(font);

            // 如果需要为其他按钮设置不同的大小，可以创建新的QFont对象
            QFont smallerFont(familyName, 16);
            ui->open_bt->setFont(smallerFont);
            ui->return_bt->setFont(smallerFont);


        }
    }
#endif
}
void maco::doorStatusChanged(){
    if(doorStatus.get()==0)
    {
        ui->open_bt->setText("        打开仓门");
    }
    else
    {
        ui->open_bt->setText("        关闭仓门");
    }
}

maco::~maco()
{
    delete ui;
}
void maco::ckcon_Slot(){
    tcts1 = new tcts();
    tcts1->infochange("提示","info","是否修改IP和端口号?",true,true);
    // 获取屏幕的中心点
    QRect screenGeometry = QApplication::desktop()->screenGeometry();
    int centerX = screenGeometry.center().x();
    int centerY = screenGeometry.center().y();
    int labelWidth = tcts1->sizeHint().width(); // 获取QLabel的建议大小
    int labelHeight = tcts1->sizeHint().height();
    int labelX = centerX-labelWidth/2;
    int labelY = centerY-labelHeight/2;
    tcts1->show();
    tcts1->move(labelX, labelY);
    connect(tcts1->ui->pushButton_2, &QPushButton::clicked,[this](){
        if(true){
            QString IP =  qtwh1->ui->ip_le->text();
            int PORT = qtwh1->ui->port_le->text().toInt();
            QStringList parts = IP.split('.');
            QString number1,number2,number3,number4;
            if (parts.count() == 4) {
                number1 = parts[0]; // 第一个数字
                number2 = parts[1]; // 第二个数字
                number3 = parts[2]; // 第三个数字
                number4 = parts[3]; // 第四个数字
            }
            QString num1 = QString("%1").arg(number1.toInt(), 2, 16, QLatin1Char('0'));
            QString num2 = QString("%1").arg(number2.toInt(), 2, 16, QLatin1Char('0'));
            QString num3 = QString("%1").arg(number3.toInt(), 2, 16, QLatin1Char('0'));
            QString num4 = QString("%1").arg(number4.toInt(), 2, 16, QLatin1Char('0'));
            QString Po = QString("%1").arg(PORT, 4, 16, QLatin1Char('0'));
            int len = 12;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString bs = "0002";
            QString bs1 = "0001";
            QByteArray byte = bs.toUtf8()+num1.toUtf8()+num2.toUtf8()+num3.toUtf8()+num4.toUtf8()+Po.toUtf8();
            QString cd1 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
            QString data = header +frame_Type4+len1+bs+bs1+num1+num2+num3+num4+Po+cd1+end_frame;
            QByteArray all;
            //分析字符串格式中是否带空格
            for(int i = 0;i<data.size();i++)
            {
                if(data[i]==' ')
                    continue;   //跳过

                int num  = data.mid(i,2).toUInt(nullptr,16);
                i++;

                all.append(num);
            }
            if(tcpClient->waitForConnected()==true){
                tcpClient->ClientSendingData(all);
                QDateTime dateTime;
                QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
                QString ss;
                for(int c :all)
                {
                    if(c>=0)
                    {
                        ss += QString(" %1")
                                .arg(c, 2, 16, QChar('0'));
                    }
                    else
                    {
                        ss += QString(" %1")
                                .arg(c+256, 2, 16, QChar('0'));
                    }
                }
            }
        }
        // 延迟0.2秒左右
        for(int i=0; i < 100000; i++)
        {
            //QCoreApplication::processEvents(QEventLoop::AllEvents);    //去处理本线程的事件循环，避免本线程被堵塞
            QCoreApplication::processEvents(QEventLoop::AllEvents, 5);//如果不够频繁，可以增加第二参数来缓解卡顿
        }
        // 子网掩码
        if(true){
            QString IP =  "255.255.255.0";
            QStringList parts = IP.split('.');
            QString number1,number2,number3,number4;
            if (parts.count() == 4) {
                number1 = parts[0]; // 第一个数字
                number2 = parts[1]; // 第二个数字
                number3 = parts[2]; // 第三个数字
                number4 = parts[3]; // 第四个数字
            }
            QString num1 = QString("%1").arg(number1.toInt(), 2, 16, QLatin1Char('0'));
            QString num2 = QString("%1").arg(number2.toInt(), 2, 16, QLatin1Char('0'));
            QString num3 = QString("%1").arg(number3.toInt(), 2, 16, QLatin1Char('0'));
            QString num4 = QString("%1").arg(number4.toInt(), 2, 16, QLatin1Char('0'));
            int len = 10;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString bs = "0002";
            QString bs1 = "0002";
            QByteArray byte = bs.toUtf8()+num1.toUtf8()+num2.toUtf8()+num3.toUtf8()+num4.toUtf8();
            QString cd1 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
            QString data = header +frame_Type4+len1+bs+bs1+num1+num2+num3+num4+cd1+end_frame;
            QByteArray all;
            //分析字符串格式中是否带空格
            for(int i = 0;i<data.size();i++)
            {
                if(data[i]==' ')
                    continue;   //跳过

                int num  = data.mid(i,2).toUInt(nullptr,16);
                i++;

                all.append(num);
            }
            if(tcpClient->waitForConnected()==true){
                tcpClient->ClientSendingData(all);
                QDateTime dateTime;
                QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
                QString ss;
                for(int c :all)
                {
                    if(c>=0)
                    {
                        ss += QString(" %1")
                                .arg(c, 2, 16, QChar('0'));
                    }
                    else
                    {
                        ss += QString(" %1")
                                .arg(c+256, 2, 16, QChar('0'));
                    }
                }
            }
        }
        // 延迟0.2秒左右
        for(int i=0; i < 100000; i++)
        {
            //QCoreApplication::processEvents(QEventLoop::AllEvents);    //去处理本线程的事件循环，避免本线程被堵塞
            QCoreApplication::processEvents(QEventLoop::AllEvents, 5);//如果不够频繁，可以增加第二参数来缓解卡顿
        }
        // 网关
        if(true){
            QString IP =  "192.168.0.1";
            QStringList parts = IP.split('.');
            QString number1,number2,number3,number4;
            if (parts.count() == 4) {
                number1 = parts[0]; // 第一个数字
                number2 = parts[1]; // 第二个数字
                number3 = parts[2]; // 第三个数字
                number4 = parts[3]; // 第四个数字
            }
            QString num1 = QString("%1").arg(number1.toInt(), 2, 16, QLatin1Char('0'));
            QString num2 = QString("%1").arg(number2.toInt(), 2, 16, QLatin1Char('0'));
            QString num3 = QString("%1").arg(number3.toInt(), 2, 16, QLatin1Char('0'));
            QString num4 = QString("%1").arg(number4.toInt(), 2, 16, QLatin1Char('0'));
            int len = 10;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString bs = "0002";
            QString bs1 = "0003";
            QByteArray byte = bs.toUtf8()+num1.toUtf8()+num2.toUtf8()+num3.toUtf8()+num4.toUtf8();
            QString cd1 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
            QString data = header +frame_Type4+len1+bs+bs1+num1+num2+num3+num4+cd1+end_frame;
            QByteArray all;
            //分析字符串格式中是否带空格
            for(int i = 0;i<data.size();i++)
            {
                if(data[i]==' ')
                    continue;   //跳过

                int num  = data.mid(i,2).toUInt(nullptr,16);
                i++;

                all.append(num);
            }
            if(tcpClient->waitForConnected()==true){
                tcpClient->ClientSendingData(all);
                QDateTime dateTime;
                QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
                QString ss;
                for(int c :all)
                {
                    if(c>=0)
                    {
                        ss += QString(" %1")
                                .arg(c, 2, 16, QChar('0'));
                    }
                    else
                    {
                        ss += QString(" %1")
                                .arg(c+256, 2, 16, QChar('0'));
                    }
                }
            }
        }
        // 延迟0.2秒左右
        for(int i=0; i < 100000; i++)
        {
            //QCoreApplication::processEvents(QEventLoop::AllEvents);    //去处理本线程的事件循环，避免本线程被堵塞
            QCoreApplication::processEvents(QEventLoop::AllEvents, 5);//如果不够频繁，可以增加第二参数来缓解卡顿
        }
        // MAC地址
        if(true){
            QStringList part1;
            for (int i = 0; i < 6; ++i) {
                QString part = QString("%1").arg(QRandomGenerator::global()->bounded(256), 2, 16, QChar('0')).toUpper();
                part1.append(part);
            }

            // 组合成一个完整的MAC地址字符串，并用-分隔
            QString macAddress = part1.join("-");
            QString IP =  macAddress;
            QStringList parts = IP.split('-');
            QString number1,number2,number3,number4,number5,number6;
            if (parts.count() == 6) {
                number1 = parts[0]; // 第一个数字
                number2 = parts[1]; // 第二个数字
                number3 = parts[2]; // 第三个数字
                number4 = parts[3]; // 第四个数字
                number5 = parts[4]; // 第五个数字
                number6 = parts[5]; // 第六个数字
            }
            int len = 12;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString bs = "0002";
            QString bs1 = "0004";
            QByteArray byte = bs.toUtf8()+number1.toUtf8()+number2.toUtf8()+number3.toUtf8()+number4.toUtf8()+number5.toUtf8()+number6.toUtf8();
            QString cd1 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
            QString data = header +frame_Type4+len1+bs+bs1+number1+number2+number3+number4+number5+number6+cd1+end_frame;
            QByteArray all;
            //分析字符串格式中是否带空格
            for(int i = 0;i<data.size();i++)
            {
                if(data[i]==' ')
                    continue;   //跳过

                int num  = data.mid(i,2).toUInt(nullptr,16);
                i++;

                all.append(num);
            }
            if(tcpClient->waitForConnected()==true){
                tcpClient->ClientSendingData(all);
                QDateTime dateTime;
                QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
                QString ss;
                for(int c :all)
                {
                    if(c>=0)
                    {
                        ss += QString(" %1")
                                .arg(c, 2, 16, QChar('0'));
                    }
                    else
                    {
                        ss += QString(" %1")
                                .arg(c+256, 2, 16, QChar('0'));
                    }
                }
                tcts1 = new tcts();
                tcts1->infochange("提示","treat","修改成功！\n注:设备保存后生效!",false,true);
                // 获取屏幕的中心点
                QRect screenGeometry = QApplication::desktop()->screenGeometry();
                int centerX = screenGeometry.center().x();
                int centerY = screenGeometry.center().y();
                int labelWidth = tcts1->sizeHint().width(); // 获取QLabel的建议大小
                int labelHeight = tcts1->sizeHint().height();
                int labelX = centerX-labelWidth/2;
                int labelY = centerY-labelHeight/2;
                tcts1->show();
                tcts1->move(labelX, labelY);
            }
        }
    });
}
// 热盖按钮
void maco::on_top_bt1_clicked()
{
    ui->top_bt1->setStyleSheet("background: #FFFFFF;border-radius: 10px;color: #222222;");
    ui->top_bt2->setStyleSheet("background-color: transparent;border-radius: 10px;color: #222222;");
    ui->top_bt3->setStyleSheet("background-color: transparent;border-radius: 10px;color: #222222;");
    ui->stackedWidget->setCurrentIndex(0);
    ui->type3_lb->setText("热盖");
    ui->label->setStyleSheet("border-image: url(:/pic/picture/whrg.png);");
}
// 荧光检测按钮
void maco::on_top_bt2_clicked()
{
    ui->top_bt2->setStyleSheet("background: #FFFFFF;border-radius: 10px;color: #222222;");
    ui->top_bt1->setStyleSheet("background-color: transparent;border-radius: 10px;color: #222222;");
    ui->top_bt3->setStyleSheet("background-color: transparent;border-radius: 10px;color: #222222;");
    ui->stackedWidget->setCurrentIndex(1);
    ui->type3_lb->setText("荧光检测");
    ui->label->setStyleSheet("border-image: url(:/pic/picture/whyg.png);");
}
// 加热块按钮
void maco::on_top_bt3_clicked()
{
    ui->top_bt3->setStyleSheet("background: #FFFFFF;border-radius: 10px;color: #222222;");
    ui->top_bt2->setStyleSheet("background-color: transparent;border-radius: 10px;color: #222222;");
    ui->top_bt1->setStyleSheet("background-color: transparent;border-radius: 10px;color: #222222;");
    ui->stackedWidget->setCurrentIndex(2);
    ui->type3_lb->setText("加热块");
    ui->label->setStyleSheet("border-image: url(:/pic/picture/whrk.png);");
}
// 旋转电机表格初始化
void maco::xztw(){
    ui->xz_tw->setRowCount(8);
    ui->xz_tw->setColumnCount(13);
    ui->xz_tw->setWindowTitle("QTableWidget & Item");
    ui->xz_tw->resizeColumnsToContents();
    ui->xz_tw->resizeRowsToContents();
    QStringList header;
    header.append(" ");
    for (int i = 1; i <= 12 ; ++i) {
        header.append(QString::number(i));
    }
    ui->xz_tw->setHorizontalHeaderLabels(header);
    ui->xz_tw->verticalHeader()->setVisible(false);
    ui->xz_tw->setItem(0,0,new QTableWidgetItem("A"));
    ui->xz_tw->setItem(1,0,new QTableWidgetItem("B"));
    ui->xz_tw->setItem(2,0,new QTableWidgetItem("C"));
    ui->xz_tw->setItem(3,0,new QTableWidgetItem("D"));
    ui->xz_tw->setItem(4,0,new QTableWidgetItem("E"));
    ui->xz_tw->setItem(5,0,new QTableWidgetItem("F"));
    ui->xz_tw->setItem(6,0,new QTableWidgetItem("G"));
    ui->xz_tw->setItem(7,0,new QTableWidgetItem("H"));

    for(int i = 0 ;i < 8 ;i++){
        for(int j = 1;j < 13;j++){
            ui->xz_tw->setItem(i,j,new QTableWidgetItem(" "));
        }
    }
    for (int row = 0; row < ui->xz_tw->rowCount(); ++row) {
        for (int col = 0; col < ui->xz_tw->columnCount(); ++col){
            ui->xz_tw->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }
    // 表头颜色
    ui->xz_tw->show();
}
// ad表格初始化
void maco::adtw(){
    ui->ad_tw->setRowCount(8);
    ui->ad_tw->setColumnCount(13);
    ui->ad_tw->setWindowTitle("QTableWidget & Item");
    ui->ad_tw->resizeColumnsToContents();
    ui->ad_tw->resizeRowsToContents();
    QStringList header;
    header.append(" ");
    for (int i = 1; i <= 12 ; ++i) {
        header.append(QString::number(i));
    }
    ui->ad_tw->setHorizontalHeaderLabels(header);
    ui->ad_tw->verticalHeader()->setVisible(false);
    ui->ad_tw->setItem(0,0,new QTableWidgetItem("A"));
    ui->ad_tw->setItem(1,0,new QTableWidgetItem("B"));
    ui->ad_tw->setItem(2,0,new QTableWidgetItem("C"));
    ui->ad_tw->setItem(3,0,new QTableWidgetItem("D"));
    ui->ad_tw->setItem(4,0,new QTableWidgetItem("E"));
    ui->ad_tw->setItem(5,0,new QTableWidgetItem("F"));
    ui->ad_tw->setItem(6,0,new QTableWidgetItem("G"));
    ui->ad_tw->setItem(7,0,new QTableWidgetItem("H"));

    for(int i = 0 ;i < 8 ;i++){
        for(int j = 1;j < 13;j++){
            ui->ad_tw->setItem(i,j,new QTableWidgetItem(" "));
        }
    }
    for (int row = 0; row < ui->ad_tw->rowCount(); ++row) {
        for (int col = 0; col < ui->ad_tw->columnCount(); ++col){
            ui->ad_tw->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }
    // 表头颜色
    ui->ad_tw->show();
}
// 水平电机表格初始化
void maco::sptw()
{
    ui->sp_tw->setRowCount(1);
    ui->sp_tw->setColumnCount(13);
    ui->sp_tw->setWindowTitle("QTableWidget & Item");
    ui->sp_tw->resizeColumnsToContents();
    ui->sp_tw->resizeRowsToContents();
    QStringList header;
    header.append(" ");
    header.append("1");
    header.append("2");
    header.append("3");
    header.append("4");
    header.append("5");
    header.append("6");
    header.append("7");
    header.append("8");
    header.append("9");
    header.append("10");
    header.append("11");
    header.append("12");
    ui->sp_tw->setItem(0,0,new QTableWidgetItem("A"));
    ui->sp_tw->setItem(1,0,new QTableWidgetItem("B"));
    ui->sp_tw->setItem(2,0,new QTableWidgetItem("C"));
    ui->sp_tw->setItem(3,0,new QTableWidgetItem("D"));
    ui->sp_tw->setItem(4,0,new QTableWidgetItem("E"));
    ui->sp_tw->setItem(5,0,new QTableWidgetItem("F"));
    ui->sp_tw->setItem(6,0,new QTableWidgetItem("G"));
    ui->sp_tw->setItem(7,0,new QTableWidgetItem("H"));
    ui->sp_tw->setHorizontalHeaderLabels(header);
    ui->sp_tw->verticalHeader()->setVisible(false);
    for (int row = 0; row < ui->sp_tw->rowCount(); ++row) {
        for (int col = 1; col < ui->sp_tw->columnCount(); ++col){
            ui->sp_tw->setItem(row,col,new QTableWidgetItem(" "));
        }
    }
    ui->sp_tw->setItem(0,0,new QTableWidgetItem("位置\n(mm)"));
    for (int row = 0; row < ui->sp_tw->rowCount(); ++row) {
        for (int col = 0; col < ui->sp_tw->columnCount(); ++col){
            ui->sp_tw->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }
    // 表头颜色
    ui->sp_tw->show();
}
// 接收消息槽函数
void maco::readyRead_Slot()
{
    if(recfl.get()==0){

    }else{
        QString Data=recvvalue.remove(QRegExp("\\s"));
        recfl.set(0);
        QString ty = Data.mid(4,4);
        QString wendubs = Data.mid(8,4);
        QString isright = Data.mid(12,4);
        QString isright2 = Data.mid(16,4);
//        qDebug()<<Data;
        if(ty=="003C"){
            if(isright=="0002"&&isright2=="0005"){
                QString addatav;
                if(litfl==1){
                    addatav=Data.mid(20,4);
                }else if(litfl==2){
                    addatav=Data.mid(24,4);
                }else if(litfl==3){
                    addatav=Data.mid(28,4);
                }else if(litfl==4){
                    addatav=Data.mid(32,4);
                }
                bool ok;
                int adval = addatav.toInt(&ok,16);
                ui->ad_tw->setItem(currentRow,currentColumn,new QTableWidgetItem(QString::number(adval)));
            }else if(isright=="0002"&&isright2=="0009"){
                QString dj = Data.mid(24,4);
                bool ok;
                int dj1 = dj.toInt(&ok,16);    //以16进制读入
                QString dj11 = QString::number(dj1);
                ui->sp_tw->setItem(0,djhlie,new QTableWidgetItem(dj11));
            }else if(isright=="0002"&&isright2=="000F"){
                QString dj = Data.mid(28,4);
                qDebug()<<dj;
                bool ok;
                int dj1 = dj.toInt(&ok,16);    //以16进制读入
                QString dj11 = QString::number(dj1);
                ui->xz_tw->setItem(currentRow,currentColumn,new QTableWidgetItem(dj11));
            }else if(isright=="0002"&&isright2=="0013"){
                QString yg = Data.mid(24,4);
                bool ok;
                int yingguang = yg.toInt(&ok,16);    //以16进制读入
                double dyg = yingguang;
                QString yg1 = QString::number(dyg/10);
                ui->qgv_le->setText(yg1);
            }else if(isright=="0004"&&isright2=="0001"){
                QString yg = Data.mid(20,4);
                bool ok;
                int yingguang = yg.toInt(&ok,16);    //以16进制读入
                double dyg = yingguang;
                QString yg1 = QString::number(dyg/100);
                ui->lineEdit->setText(yg1);
                yg = Data.mid(24,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_2->setText(yg1);
                yg = Data.mid(28,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_3->setText(yg1);
                yg = Data.mid(32,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_4->setText(yg1);
                yg = Data.mid(36,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_6->setText(yg1);
                yg = Data.mid(40,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_8->setText(yg1);
                yg = Data.mid(44,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_5->setText(yg1);
                yg = Data.mid(48,4);
                ok;
                yingguang = yg.toInt(&ok,16);    //以16进制读入
                dyg = yingguang;
                yg1 = QString::number(dyg/100);
                ui->lineEdit_7->setText(yg1);
            }else if(isright=="000A"&&isright2=="000A"&&Data.mid(20,4)=="0001"){
                int kbfl=24;
                for(int i = 0; i < 8 ; i++){
                    for(int j = 1;j < 49; j++){
                        QString kdata = Data.mid(kbfl,4);
                        int kdatai;
                        bool ok;
                        kdatai = kdata.toInt(&ok,16);    //以16进制读入
                        double kdatad = kdatai;
                        QString kdatas = QString::number(kdatad);
                        ui->bj_tab->setItem(i,j,new QTableWidgetItem(kdatas));
                        kbfl+=4;
                    }
                }
            }
        }else if(ty=="003D"){
            if(isright=="0001"&&isright2=="0002"){
                QString wen = Data.mid(20,4);
                bool ok;
                int wendu = wen.toInt(&ok,16);    //以16进制读入
                double wd = wendu;
                QString wd1 = QString::number(wd/100);
                ui->rgwd_le->setText(wd1);
            }else if(isright=="0004"&&isright2=="0001"){
                int kbfl=20;
                for(int i = 0; i < 12 ; i++){
                    for(int j = 1;j < 9; j++){
                        QString kdata = Data.mid(kbfl,4);
                        int kdatai;
                        bool ok;
                        kdatai = kdata.toInt(&ok,16);    //以16进制读入
                        double kdatad = kdatai;
                        QString kdatas = QString::number(kdatad/100, 'f', 2);
                        ui->sjwtab_tw->setItem(i,j,new QTableWidgetItem(kdatas));
                        kbfl+=4;
                    }
                }
            }else if(isright=="0004"&&isright2=="000A"){
                int kbfl=20;
                for(int i = 1; i < 7 ; i++){
                    for(int j = 0;j < 2; j++){
                        QString kdata = Data.mid(kbfl,4);
                        int kdatai;
                        bool ok;
                        if(kdata.left(1)=="a"||kdata.left(1)=="b"||kdata.left(1)=="c"||kdata.left(1)=="d"||kdata.left(1)=="e"||kdata.left(1)=="f"){
                            kdatai = -(65536-kdata.toInt(&ok,16));
                        }else{
                            kdatai = kdata.toInt(&ok,16);    //以16进制读入
                        }
                        double kdatad = kdatai;
                        QString kdatas = QString::number(kdatad/100, 'f', 2);
                        ui->kb_tw->setItem(j,i,new QTableWidgetItem(kdatas));
                        kbfl+=4;
                    }
                }
            }else if (isright=="000F"&&isright2=="0001") {
                QString wen = Data.mid(20,4);
                bool ok;
                int wendu = wen.toInt(&ok,16);    //以16进制读入
                double wd = wendu;
                QString wd1 = QString::number(wd/100);
                ui->bs_le_2->setText(wd1);
            }
        }else if(ty=="003E"){

        }
    }
}
// 串口接收消息槽函数
void maco::serialPortRead_Slot(){
    buffer.clear();
    buffer = serialPort->readAll();
    QString ss;
    for(int c :buffer)
    {
        if(c>=0)
        {
            ss += QString(" %1")
                    .arg(c, 2, 16, QChar('0'));
        }
        else
        {
            ss += QString(" %1")
                    .arg(c+256, 2, 16, QChar('0'));
        }
    }
    QString Data=ss.remove(QRegExp("\\s"));
    QString ty = Data.mid(4,4);
    QString wendubs = Data.mid(8,4);
    QString isright = Data.mid(12,4);
    QString isright2 = Data.mid(16,4);
    QString rw = Data.mid(50,2);
    if(ty=="003c"){
        if(isright=="0002"&&isright2=="0005"){
            QString addatav;
            if(litfl==1){
                addatav=Data.mid(20,4);
            }else if(litfl==2){
                addatav=Data.mid(24,4);
            }else if(litfl==3){
                addatav=Data.mid(28,4);
            }else if(litfl==4){
                addatav=Data.mid(32,4);
            }
            bool ok;
            int adval = addatav.toInt(&ok,16);
            ui->ad_tw->setItem(currentRow,currentColumn,new QTableWidgetItem(QString::number(adval)));
        }else if(isright=="0002"&&isright2=="0009"){
            QString dj = Data.mid(24,4);
            bool ok;
            int dj1 = dj.toInt(&ok,16);    //以16进制读入
            QString dj11 = QString::number(dj1);
            ui->sp_tw->setItem(0,djhlie,new QTableWidgetItem(dj11));
        }else if(isright=="0002"&&isright2=="000f"){
            QString dj = Data.mid(28,4);
            qDebug()<<dj;
            bool ok;
            int dj1 = dj.toInt(&ok,16);    //以16进制读入
            QString dj11 = QString::number(dj1);
            ui->xz_tw->setItem(currentRow,currentColumn,new QTableWidgetItem(dj11));
        }else if(isright=="0002"&&isright2=="0013"){
            QString yg = Data.mid(24,4);
            bool ok;
            int yingguang = yg.toInt(&ok,16);    //以16进制读入
            double dyg = yingguang;
            QString yg1 = QString::number(dyg/10);
            ui->qgv_le->setText(yg1);
        }
    }else if(ty=="003d"){
        if(isright=="0001"&&isright2=="0002"){
            QString wen = Data.mid(20,4);
            bool ok;
            int wendu = wen.toInt(&ok,16);    //以16进制读入
            double wd = wendu;
            QString wd1 = QString::number(wd/100);
            ui->rgwd_le->setText(wd1);
        }else if(isright=="0004"&&isright2=="0001"){
            int kbfl=20;
            for(int i = 0; i < 12 ; i++){
                for(int j = 1;j < 9; j++){
                    QString kdata = Data.mid(kbfl,4);
                    int kdatai;
                    bool ok;
                    kdatai = kdata.toInt(&ok,16);    //以16进制读入
                    double kdatad = kdatai;
                    QString kdatas = QString::number(kdatad/100, 'f', 2);
                    ui->sjwtab_tw->setItem(i,j,new QTableWidgetItem(kdatas));
                    kbfl+=4;
                }
            }
        }else if(isright=="0004"&&isright2=="000a"){
            QString kdata = Data.mid(24,4);
            QString bdata = Data.mid(28,4);
            int kdatai;
            int bdatai;
            bool ok;
            QString isright3 = Data.mid(20,4);
            int lie = isright3.toInt(&ok,16);
            if(kdata.left(1)=="a"||kdata.left(1)=="b"||kdata.left(1)=="c"||kdata.left(1)=="d"||kdata.left(1)=="e"||kdata.left(1)=="f"){
                kdatai = -(65536-kdata.toInt(&ok,16));
            }else{
                kdatai = kdata.toInt(&ok,16);    //以16进制读入
            }
            if(bdata.left(1)=="a"||bdata.left(1)=="b"||bdata.left(1)=="c"||bdata.left(1)=="d"||bdata.left(1)=="e"||bdata.left(1)=="f"){
                bdatai = -(65536-bdata.toInt(&ok,16));
            }else{
                bdatai = bdata.toInt(&ok,16);    //以16进制读入
            }
            double kdatad = kdatai;
            double bdatad = bdatai;
            QString kdatas = QString::number(kdatad/100, 'f', 2);
            QString bdatas = QString::number(bdatad/100, 'f', 2);
            ui->kb_tw->setItem(0,lie,new QTableWidgetItem(kdatas));
            ui->kb_tw->setItem(1,lie,new QTableWidgetItem(bdatas));
        }
    }else if(ty=="003E"){
        if(isright=="0004"&&isright2=="0001"){
            int kbfl=20;
            for(int i = 0; i < 8 ; i++){
                for(int j = 1;j < 49; j++){
                    QString kdata = Data.mid(kbfl,4);
                    int kdatai;
                    bool ok;
                    kdatai = kdata.toInt(&ok,16);    //以16进制读入
                    double kdatad = kdatai;
                    QString kdatas = QString::number(kdatad/100, 'f', 2);
                    ui->bj_tab->setItem(i,j,new QTableWidgetItem(kdatas));
                    kbfl+=4;
                }
            }
        }
    }
}
// 串口发送数据
void maco::serialPortSend_Slot(QByteArray data){
    if(serialPort->isOpen()){
        serialPort->write(data);
    }
}
// 热盖温度读取
void maco::on_rgwd_bt1_clicked()
{
    if(true){
        QString type = "0001";
        QString type2 = "0002";
        QString wen2 = "0000";
        QString end2 = "0000";
        int len = 10;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+wen2+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
//        rgfl = 1;
//        ui->rgwd_bt1->setEnabled(false);
//        ui->rgwd_bt1->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
//        ui->rgwd_bt2->setEnabled(true);
//        ui->rgwd_bt2->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 热盖升温停止
void maco::on_rgwd_bt2_clicked()
{
    if(true){
        QString type = "0001";
        QString type2 = "0003";
        QString wen2 = "0000";
        QString end2 = "0000";
        int len = 10;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+wen2+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
//        rgfl = 0;
//        ui->rgwd_bt2->setEnabled(false);
//        ui->rgwd_bt2->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
//        ui->rgwd_bt1->setEnabled(true);
//        ui->rgwd_bt1->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }
}
// 热盖设置温度
void maco::on_rgwd_bt3_clicked()
{
    QString type = "0001";
    QString type2 = "0001";
    double wen = ui->rgwd_le->text().toDouble()*100;
    int wen1 = wen;
    QString wen2 = QString("%1").arg(wen1, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 10;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+wen2+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 荧光灯开关
void maco::on_dkg_cb_currentTextChanged(const QString &arg1)
{
    if(dgfl==0){
        if(arg1=="FAM 通道开"){
            litopfl=1;
            QString type = "0002";
            QString type2 = "0001";
            QString type3 = "0001";
            QString end2 = "0000";
            int len = 10;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
            QString finalData;
            for (int i = 0; i < data.length(); ++i) {
                finalData.append(data.at(i));
                // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
                if ((i+1)%2==0) {
                    finalData.append(' ');
                }
            }
            QByteArray finalInfo=common->GetSendData(finalData);
            tcpClient->ClientSendingData(finalInfo);
            serialPortSend_Slot(finalInfo);
        }else if(arg1=="VIC 通道开"){
            litopfl=2;
            QString type = "0002";
            QString type2 = "0001";
            QString type3 = "0002";
            QString end2 = "0000";
            int len = 10;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
            QString finalData;
            for (int i = 0; i < data.length(); ++i) {
                finalData.append(data.at(i));
                // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
                if ((i+1)%2==0) {
                    finalData.append(' ');
                }
            }
            QByteArray finalInfo=common->GetSendData(finalData);
            tcpClient->ClientSendingData(finalInfo);
            serialPortSend_Slot(finalInfo);
        }else if(arg1=="ROX 通道开"){
            litopfl=3;
            QString type = "0002";
            QString type2 = "0001";
            QString type3 = "0003";
            QString end2 = "0000";
            int len = 10;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
            QString finalData;
            for (int i = 0; i < data.length(); ++i) {
                finalData.append(data.at(i));
                // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
                if ((i+1)%2==0) {
                    finalData.append(' ');
                }
            }
            QByteArray finalInfo=common->GetSendData(finalData);
            tcpClient->ClientSendingData(finalInfo);
            serialPortSend_Slot(finalInfo);
        }else if(arg1=="CY5 通道开"){
            litopfl=4;
            QString type = "0002";
            QString type2 = "0001";
            QString type3 = "0004";
            QString end2 = "0000";
            int len = 10;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
            QString finalData;
            for (int i = 0; i < data.length(); ++i) {
                finalData.append(data.at(i));
                // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
                if ((i+1)%2==0) {
                    finalData.append(' ');
                }
            }
            QByteArray finalInfo=common->GetSendData(finalData);
            tcpClient->ClientSendingData(finalInfo);
            serialPortSend_Slot(finalInfo);
        }
        dgfl = 1;
        ui->dqk_bt->setEnabled(false);
        ui->dqk_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->dqg_bt->setEnabled(true);
        ui->dqg_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
        if(arg1=="操作"){
            dgfl = 0;
            ui->dqg_bt->setEnabled(false);
            ui->dqg_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
            ui->dqk_bt->setEnabled(true);
            ui->dqk_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
        }
    }

}
// 灯全开
void maco::on_dqk_bt_clicked()
{
    if(dgfl==0){
        litopfl=5;
        QString type = "0002";
        QString type2 = "0003";
        QString type3 = "0005";
        QString end2 = "0000";
        int len = 10;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        dgfl = 1;
        ui->dqk_bt->setEnabled(false);
        ui->dqk_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->dqg_bt->setEnabled(true);
        ui->dqg_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 灯全关
void maco::on_dqg_bt_clicked()
{
    if(dgfl==1){
        litopfl=0;
        QString type = "0002";
        QString type2 = "0004";
        QString type3 = "0005";
        QString end2 = "0000";
        int len = 10;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        dgfl = 0;
        ui->dqg_bt->setEnabled(false);
        ui->dqg_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->dqk_bt->setEnabled(true);
        ui->dqk_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 通道选择
void maco::on_ygtd_cb_activated(const QString &arg1)
{
    if(arg1=="FAM"){
        litfl=1;
    }else if(arg1=="VIC"){
        litfl=2;
    }else if(arg1=="ROX"){
        litfl=3;
    }else if(arg1=="CY5"){
        litfl=4;
    }
}
// AD单次采集
void maco::on_ad1time_bt_clicked()
{
    QString type = "0002";
    QString type2 = "0005";
    QString type3 = "0000";
    QString end2 = "0000";
    int len = 10;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+type+type2+type3+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// AD连续采集
void maco::on_adtimes_bt_clicked()
{
    int adtimes = ui->adtime_le->text().toInt();
    if(ads==0){
        int z = ui->adti_le->text().toInt();
        int cyc5;
        if(z==0){
            cyc5 = 200;
        }else{
            cyc5 = z;
        }
        timSend5->setInterval(cyc5);
        connect(timSend5,&QTimer::timeout,this,[=]()
        {
            on_ad1time_bt_clicked();
            adfl++;
            if(adfl>=adtimes){
                disconnect(timSend5,0,0,0);
                timSend5->stop();
                ui->adtimes_bt->setText("连续采集");
                adfl=0;
                ads=0;
            }
        });
        timSend5->start();
        ui->adtimes_bt->setText("关闭采集");
        ads=1;
    }else if(ads==1){
        disconnect(timSend5,0,0,0);
        timSend5->stop();
        ui->adtimes_bt->setText("连续采集");
        adfl=0;
        ads=0;
    }
}
// AD采集页面运动
void maco::on_adyd_bt_clicked()
{
    // 检查是否有选中的单元格
    if (ui->ad_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->ad_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        QString type = "0002";
        QString type2 = "000D";
        int kong = currentRow+1+(currentColumn-1)*8;;
        QString type3 = QString("%1").arg(kong, 4, 16, QLatin1Char('0'));
        QString type4 = QString("%1").arg(litfl, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
    }
}
// 横向电机读取
void maco::on_spr_bt_clicked()
{
    if (ui->sp_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->sp_tw->currentIndex();
        currentColumn = currentIndex.column();
        djhlie = currentColumn;
        QString type = "0002";
        QString type2 = "0009";
        QString type3 = QString("%1").arg(currentIndex.column(), 4, 16, QLatin1Char('0'));
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
    }
}
// 横向电机写入
void maco::on_spw_bt_clicked()
{
    if (ui->sp_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->sp_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        djhlie = currentColumn;
        QString type = "0002";
        QString type2 = "000A";
        QString type3 = QString("%1").arg(currentIndex.column(), 4, 16, QLatin1Char('0'));
        QString type4 = QString("%1").arg(ui->sp_tw->item(currentRow,currentColumn)->text().toInt(), 4, 16, QLatin1Char('0'));
        QString slie = "param_"+QString::number(djhlie);
        QString sql="UPDATE Settings SET " + slie + "=:newValue WHERE ID=25";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":newValue", ui->sp_tw->item(currentRow,currentColumn)->text()); // 绑定新的值
        if (!query.exec()) {
            qDebug() << "Error:" << query.lastError().text();
        }
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
    }
}
// 横向电机运动
void maco::on_spy_bt_clicked()
{
    if (ui->sp_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->sp_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        djhlie = currentColumn;
        QString type = "0002";
        QString type2 = "0007";
        QString type3 = QString("%1").arg(currentIndex.column(), 4, 16, QLatin1Char('0'));
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
    }
}
// 横向电机复位
void maco::on_spf_bt_clicked()
{
    if (ui->sp_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->sp_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        djhlie = currentColumn;
        QString type = "0002";
        QString type2 = "0008";
        QString type3 = "0000";
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
    }
}
// 横向电机润脂测试
void maco::on_sprte_bt_clicked()
{
    if(spdjfl==0){
        QString type = "0002";
        QString type2 = "000B";
        QString type3 = "0000";
        if(ui->sps_cb->currentText()=="高"){
            type3="0001";
        }else if(ui->sps_cb->currentText()=="中"){
            type3="0002";
        }else if(ui->sps_cb->currentText()=="低"){
            type3="0003";
        }
        QString type4 = QString("%1").arg(ui->spt_le->text().toInt(), 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        spdjfl = 1;
        ui->sprte_bt->setEnabled(false);
        ui->sprte_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->sprst_bt->setEnabled(true);
        ui->sprst_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 横向电机润脂停止
void maco::on_sprst_bt_clicked()
{
    if(spdjfl==1){
        QString type = "0002";
        QString type2 = "000C";
        QString type3 = "0000";
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        spdjfl = 0;
        ui->sprst_bt->setEnabled(false);
        ui->sprst_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->sprte_bt->setEnabled(true);
        ui->sprte_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 旋转电机读取
void maco::on_xzr_bt_clicked()
{
    // 检查是否有选中的单元格
    if (ui->xz_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->xz_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        QString type="0002";
        QString type2="000F";
        int kong = currentRow+1+(currentColumn-1)*8;
        QString type3 = QString("%1").arg(kong, 4, 16, QLatin1Char('0'));
        QString type4 = QString("%1").arg(litopfl, 4, 16, QLatin1Char('0'));
        QString zw = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 14;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+zw+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        qDebug() << "Selected cell is at row:" << currentRow << "column:" << currentColumn;
    } else {
        qDebug() << "No cell is selected.";
    }
}
// 旋转电机写入
void maco::on_xzw_bt_clicked()
{
    // 检查是否有选中的单元格
    if (ui->xz_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->xz_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        QString type="0002";
        QString type2="0010";
        int kong = currentRow+1+(currentColumn-1)*8;
        QString type3 = QString("%1").arg(kong, 4, 16, QLatin1Char('0'));
        QString type4 = QString("%1").arg(litopfl, 4, 16, QLatin1Char('0'));
        QString zw = QString("%1").arg(ui->xz_tw->item(currentRow,currentColumn)->text().toInt(), 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 14;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+zw+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        qDebug() << "Selected cell is at row:" << currentRow << "column:" << currentColumn;
    } else {
        qDebug() << "No cell is selected.";
    }
}
// 旋转电机运动
void maco::on_xzy_bt_clicked()
{
    // 检查是否有选中的单元格
    if (ui->xz_tw->currentIndex().isValid()) {
        QModelIndex currentIndex = ui->xz_tw->currentIndex();
        currentRow = currentIndex.row();
        currentColumn = currentIndex.column();
        QString type="0002";
        QString type2="000D";
        int kong = currentRow+1+(currentColumn-1)*8;
        QString type3 = QString("%1").arg(kong, 4, 16, QLatin1Char('0'));
        QString type4 = QString("%1").arg(litopfl, 4, 16, QLatin1Char('0'));
        QString zw = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 14;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+zw+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        qDebug() << "Selected cell is at row:" << currentRow << "column:" << currentColumn;
    } else {
        qDebug() << "No cell is selected.";
    }
}
// 旋转电机复位
void maco::on_xzf_bt_clicked()
{
    QString type="0002";
    QString type2="000E";
    QString type3 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString zw = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 14;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+type+type2+type3+type4+zw+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 旋转电机润脂测试
void maco::on_xzrte_bt_clicked()
{
    if(xzdjfl==0){
        QString type = "0002";
        QString type2 = "0011";
        QString type3 = "0000";
        if(ui->xzs_cb->currentText()=="高"){
            type3="0001";
        }else if(ui->xzs_cb->currentText()=="中"){
            type3="0002";
        }else if(ui->xzs_cb->currentText()=="低"){
            type3="0003";
        }
        QString type4 = QString("%1").arg(ui->xzt_le->text().toInt(), 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        xzdjfl=1;
        ui->xzrte_bt->setEnabled(false);
        ui->xzrte_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->xzrst_bt->setEnabled(true);
        ui->xzrst_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }
}
// 旋转电机润脂停止
void maco::on_xzrst_bt_clicked()
{
    if(xzdjfl==1){
        QString type = "0002";
        QString type2 = "0012";
        QString type3 = "0000";
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        xzdjfl=0;
        ui->xzrst_bt->setEnabled(false);
        ui->xzrst_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->xzrte_bt->setEnabled(true);
        ui->xzrte_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 光强通道选择
void maco::on_gqt_cb_activated(const QString &arg1)
{
    if(arg1=="FAM"){
        litqrfl=1;
    }else if(arg1=="VIC"){
        litqrfl=2;
    }else if(arg1=="ROX"){
        litqrfl=3;
    }else if(arg1=="CY5"){
        litqrfl=4;
    }
}
// 光强读取
void maco::on_gqr_bt_clicked()
{
    QString type = "0002";
    QString type2 = "0013";
    QString type3 = QString("%1").arg(litqrfl, 4, 16, QLatin1Char('0'));
    QString type4 = "0000";
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 光强写入
void maco::on_gqw_bt_clicked()
{
    QString type = "0002";
    QString type2 = "0014";
    QString type3 = QString("%1").arg(litqrfl, 4, 16, QLatin1Char('0'));
    QString type4 = QString("%1").arg(ui->qgv_le->text().toInt(), 4, 16, QLatin1Char('0'));
    QString slie = "param_"+QString::number(litqrfl);
    QString sql="UPDATE Settings SET " + slie + "=:newValue WHERE ID=20";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    query.prepare(sql);
    query.bindValue(":newValue", ui->qgv_le->text()); // 绑定新的值
    if (!query.exec()) {
        qDebug() << "Error:" << query.lastError().text();
    }
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 打开仓门
void maco::on_cmk_bt_clicked()
{
    if(cmfl==0){
        QString type = "0003";
        QString type2 = "0001";
        QString type3 = QString("%1").arg(ui->pzv_le->text().toInt(), 4, 16, QLatin1Char('0'));
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QString slie = "param_"+QString::number(2);
        QString sql="UPDATE Settings SET " + slie + "=:newValue WHERE ID=15";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":newValue", ui->pzv_le->text()); // 绑定新的值
        if (!query.exec()) {
            qDebug() << "Error:" << query.lastError().text();
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        cmfl = 1;
        ui->cmk_bt->setEnabled(false);
        ui->cmk_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->cmg_bt->setEnabled(true);
        ui->cmg_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 关闭仓门
void maco::on_cmg_bt_clicked()
{
    if(cmfl==1){
        QString type = "0003";
        QString type2 = "0002";
        QString type3 = QString("%1").arg(ui->pzv_le->text().toInt(), 4, 16, QLatin1Char('0'));
        QString type4 = "0000";
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QString slie = "param_"+QString::number(1);
        QString sql="UPDATE Settings SET " + slie + "=:newValue WHERE ID=15";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":newValue", ui->pzv_le->text()); // 绑定新的值
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        cmfl = 0;
        ui->cmg_bt->setEnabled(false);
        ui->cmg_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->cmk_bt->setEnabled(true);
        ui->cmk_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 电机上升
void maco::on_djss_bt_clicked()
{
    QString type = "0003";
    QString type2 = "0003";
    QString type3 = QString("%1").arg(hctype, 4, 16, QLatin1Char('0'));
    QString type4 = QString("%1").arg(ui->bs_le->text().toInt(), 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 耗材类型选择
void maco::on_hclx_cb_activated(const QString &arg1)
{
    if(arg1=="八连排"){
        hctype=1;
    }else if(arg1=="单管"){
        hctype=2;
    }else if(arg1=="有裙边"){
        hctype=3;
    }else if(arg1=="无裙边"){
        hctype=4;
    }
}
// 电机复位
void maco::on_djfw_bt_clicked()
{
    QString type = "0003";
    QString type2 = "0004";
    QString type3 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 加热块润脂测试
void maco::on_rkrzcs_bt_clicked()
{
    if(rkfl==0){
        QString type = "0003";
        QString type2 = "0005";
        QString type3 = "0000";
        if(ui->sps_cb->currentText()=="高"){
            type3="0001";
        }else if(ui->sps_cb->currentText()=="中"){
            type3="0002";
        }else if(ui->sps_cb->currentText()=="低"){
            type3="0003";
        }
        QString type4 = QString("%1").arg(ui->rgrzt_bt->text().toInt(), 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        rkfl = 1;
        ui->rkrzcs_bt->setEnabled(false);
        ui->rkrzcs_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->rktzrz_bt->setEnabled(true);
        ui->rktzrz_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }
}
// 加热块润脂停止
void maco::on_rktzrz_bt_clicked()
{
    if(rkfl==1){
        QString type = "0003";
        QString type2 = "0006";
        QString type3 = "0000";
        QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        rkfl = 0;
        ui->rktzrz_bt->setEnabled(false);
        ui->rktzrz_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->rkrzcs_bt->setEnabled(true);
        ui->rkrzcs_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 升降温参数读取
void maco::on_sjwr_bt_clicked()
{
    QString type = "0004";
    QString type2 = "0001";
    QString type3 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 10;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 升降温参数写入
void maco::on_sjww_bt_clicked()
{
    QString type = "0004";
    QString type2 = "0002";
    QString ty;
    ty.append(type);
    ty.append(type2);
    for(int i=0;i<12;i++){
        for(int j=1;j<9;j++){
            int datava;
            datava = QString::number(ui->sjwtab_tw->item(i,j)->text().toDouble()*100).toInt();
            ty.append(QString("%1").arg(datava, 4, 16, QLatin1Char('0')));
        }
    }
    QString end2 = "0000";
    int len = 200;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+ty+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 升降温表格初始化
void maco::sjwtab(){
    ui->sjwtab_tw->setRowCount(12);
    ui->sjwtab_tw->setColumnCount(9);
    ui->sjwtab_tw->setWindowTitle("QTableWidget & Item");
    ui->sjwtab_tw->resizeColumnsToContents();
    ui->sjwtab_tw->resizeRowsToContents();
    QStringList header;
    header<<"升降温"<<"斜率K"<<"温度1"<<"K1"<<"K2"<<"温度2"<<"P"<<"I"<<"D";
    ui->sjwtab_tw->setHorizontalHeaderLabels(header);
    ui->sjwtab_tw->verticalHeader()->setVisible(false);
    ui->sjwtab_tw->setItem(0,0,new QTableWidgetItem("A区升温"));
    ui->sjwtab_tw->setItem(1,0,new QTableWidgetItem("A区降温"));
    ui->sjwtab_tw->setItem(2,0,new QTableWidgetItem("B区升温"));
    ui->sjwtab_tw->setItem(3,0,new QTableWidgetItem("B区降温"));
    ui->sjwtab_tw->setItem(4,0,new QTableWidgetItem("C区升温"));
    ui->sjwtab_tw->setItem(5,0,new QTableWidgetItem("C区降温"));
    ui->sjwtab_tw->setItem(6,0,new QTableWidgetItem("D区升温"));
    ui->sjwtab_tw->setItem(7,0,new QTableWidgetItem("D区降温"));
    ui->sjwtab_tw->setItem(8,0,new QTableWidgetItem("E区升温"));
    ui->sjwtab_tw->setItem(9,0,new QTableWidgetItem("E区降温"));
    ui->sjwtab_tw->setItem(10,0,new QTableWidgetItem("F区升温"));
    ui->sjwtab_tw->setItem(11,0,new QTableWidgetItem("F区降温"));

    for(int i = 0 ;i < 12 ;i++){
        for(int j = 1;j < 9;j++){
            ui->sjwtab_tw->setItem(i,j,new QTableWidgetItem(" "));
        }
    }
    for (int row = 0; row < ui->sjwtab_tw->rowCount(); ++row) {
        for (int col = 0; col < ui->sjwtab_tw->columnCount(); ++col){
            ui->sjwtab_tw->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }
    // 表头颜色
    ui->sjwtab_tw->show();
}
// 升温测试
void maco::on_sw_bt_clicked()
{
    if(sjwfll==0){
        QString type = "0004";
        QString type2 = "0005";
        double gl = ui->sw_le->text().toDouble();
        int gll = gl*100;
        QString gl1 = QString("%1").arg(gll, 4, 16, QLatin1Char('0'));
        double rg = ui->rgwdsj_le->text().toDouble();
        int rgg = rg*100;
        QString rg1 = QString("%1").arg(rgg, 4, 16, QLatin1Char('0'));
        double sl = ui->slsj_le->text().toDouble();
        int sll = sl*100;
        QString sl1 = QString("%1").arg(sll, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 16;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+gl1+rg1+sl1+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        sjwfll = 1;
        ui->sw_bt->setEnabled(false);
        ui->sw_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->jw_bt->setEnabled(false);
        ui->jw_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->sjws_bt->setEnabled(true);
        ui->sjws_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 降温测试
void maco::on_jw_bt_clicked()
{
    if(sjwfll == 0){
        QString type = "0004";
        QString type2 = "0006";
        double gl = ui->jw_le->text().toDouble();
        int gll = gl*100;
        QString gl1 = QString("%1").arg(gll, 4, 16, QLatin1Char('0'));
        double rg = ui->rgwdsj_le->text().toDouble();
        int rgg = rg*100;
        QString rg1 = QString("%1").arg(rgg, 4, 16, QLatin1Char('0'));
        double sl = ui->slsj_le->text().toDouble();
        int sll = sl*100;
        QString sl1 = QString("%1").arg(sll, 4, 16, QLatin1Char('0'));
        int len = 16;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        QString data = header+frame_Type4+len1+type+type2+gl1+rg1+sl1+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        sjwfll = 1;
        ui->sw_bt->setEnabled(false);
        ui->sw_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->jw_bt->setEnabled(false);
        ui->jw_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->sjws_bt->setEnabled(true);
        ui->sjws_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }
}
// 停止测试
void maco::on_sjws_bt_clicked()
{
    if(sjwfll == 1){
        QString type = "0004";
        QString type2 = "0009";
        QString type3 = "0000";
        QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        sjwfll = 0;
        ui->sw_bt->setEnabled(true);
        ui->sw_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
        ui->jw_bt->setEnabled(true);
        ui->jw_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
        ui->sjws_bt->setEnabled(false);
        ui->sjws_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
    }
}
// 加热测试
void maco::on_jr_bt_clicked()
{
    if(jjfl==0){
        QString type = "0004";
        QString type2 = "0007";
        int gl = ui->jr_le->text().toInt();
        QString gl1 = QString("%1").arg(gl, 4, 16, QLatin1Char('0'));
        int rg = ui->glsj_le->text().toInt();
        QString rg1 = QString("%1").arg(rg*100, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+gl1+rg1+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        jjfl = 1;
        ui->jr_bt->setEnabled(false);
        ui->jr_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->zl_bt->setEnabled(false);
        ui->zl_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->jzs_bt->setEnabled(true);
        ui->jzs_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 制冷测试
void maco::on_zl_bt_clicked()
{
    if(jjfl==0){
        QString type = "0004";
        QString type2 = "0008";
        int gl = ui->zl_le->text().toInt();
        QString gl1 = QString("%1").arg(gl, 4, 16, QLatin1Char('0'));
        int rg = ui->glsj_le->text().toInt();
        QString rg1 = QString("%1").arg(rg*100, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+gl1+rg1+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        jjfl = 1;
        ui->jr_bt->setEnabled(false);
        ui->jr_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->zl_bt->setEnabled(false);
        ui->zl_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
        ui->jzs_bt->setEnabled(true);
        ui->jzs_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
    }

}
// 停止测试
void maco::on_jzs_bt_clicked()
{
    if(jjfl==1){
        QString type = "0004";
        QString type2 = "0009";
        QString type3 = "0000";
        QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
        QString end2 = "0000";
        int len = 12;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i) {
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
        jjfl = 0;
        ui->jr_bt->setEnabled(true);
        ui->jr_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
        ui->zl_bt->setEnabled(true);
        ui->zl_bt->setStyleSheet("background: #2F42CD;border-radius: 8px; color: rgb(255, 255, 255);");
        ui->jzs_bt->setEnabled(false);
        ui->jzs_bt->setStyleSheet("background: #F5F5F5;border-radius: 8px;border: 1px solid #D9D9D9;color: #BFBFBF;");
    }
}
// K、B值表格初始化
void maco::kbtw(){
    ui->kb_tw->setRowCount(2);
    ui->kb_tw->setColumnCount(7);
    ui->kb_tw->setWindowTitle("QTableWidget & Item");
    ui->kb_tw->resizeColumnsToContents();
    ui->kb_tw->resizeRowsToContents();
    QStringList header;
    header<<" "<<"A"<<"B"<<"C"<<"D"<<"E"<<"F";
    ui->kb_tw->setHorizontalHeaderLabels(header);
    ui->kb_tw->verticalHeader()->setVisible(false);
    ui->kb_tw->setItem(0,0,new QTableWidgetItem("K值"));
    ui->kb_tw->setItem(1,0,new QTableWidgetItem("B值"));
    for(int i = 0 ;i < 2 ;i++){
        for(int j = 1;j < 7;j++){
            ui->kb_tw->setItem(i,j,new QTableWidgetItem(" "));
        }
    }
    for (int row = 0; row < ui->kb_tw->rowCount(); ++row) {
        for (int col = 0; col < ui->kb_tw->columnCount(); ++col){
            ui->kb_tw->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }
    // 表头颜色
    ui->kb_tw->show();
}
// K、B值读取
void maco::on_kbr_bt_clicked()
{
    QString type = "0004";
    QString type2 = "000A";
    QString type3 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString type5 = "0000";
    QString end2 = "0000";
    int len = 14;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+type5+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    qDebug()<<"发"<<finalData;
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// K、B值写入
void maco::on_kbw_bt_clicked()
{
    QString kvv;
    QMap<QString, int> keywordToValue = {
        {"A", 1},
        {"B", 2},
        {"C", 3},
        {"D", 4},
        {"E", 5},
        {"F", 6}
    };
    QString kw = "A";
    int len = 32;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString type = "0004";
    QString type2 = "000B";
    QString data = type+type2;
    int kv;
    QByteArray byteArray = kw.toUpper().toLatin1();
    char firstChar = byteArray.at(0);
    int rowIndex = firstChar - 'A'; // 将'A'到'F'转换为0到5的索引
    double v1;
    for(int i=1;i<7;i++){
        for (int j=0;j<2;j++) {
            v1 = ui->kb_tw->item(j,i)->text().toDouble()*100;
            if (rowIndex >= 0 && rowIndex < 6) { // 确保索引在有效范围内
                kv = v1;
            }
            if(kv<0){
                QString kvv1 = QString("%1").arg(kv, 4, 16, QLatin1Char('0'));
                kvv=kvv1.right(4);
            }else{
                kvv = QString("%1").arg(kv, 4, 16, QLatin1Char('0'));
            }
            data.append(kvv);
        }
    }
    QString end2 = "0000";
    QString data2 = header+frame_Type4+len1+data+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data2.length(); ++i) {
        finalData.append(data2.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    qDebug()<<"发"<<finalData;
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);

}
// 主控复位
void maco::on_bot_bt3_clicked()
{
    QString type = "0005";
    QString type2 = "0002";
    QString type3 = "0000";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
    QMessageBox::information(this,"提示","复位成功");
}
// 主控保存
void maco::on_bot_bt4_clicked()
{
    QString type = "0005";
    QString type2 = "0001";
    QString type3 = "0000";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
    QMessageBox::information(this,"提示","保存成功");
}
// 其他维护
void maco::on_bot_bt2_clicked()
{
    qtwh1->show();
    // 获取屏幕的中心点
    QRect screenGeometry = QApplication::desktop()->screenGeometry();
    int centerX = screenGeometry.center().x();
    int centerY = screenGeometry.center().y();
    int labelWidth = qtwh1->sizeHint().width(); // 获取QLabel的建议大小
    int labelHeight = qtwh1->sizeHint().height();
    int labelX = centerX-220;
    int labelY = centerY-162;
    qtwh1->show();
    qtwh1->move(labelX, labelY);
}
// 水泵开
void maco::sbo_Slot(){
    QString type = "0006";
    QString type2 = "0001";
    QString type3 = "0000";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 水泵关
void maco::sbc_Slot(){
    QString type = "0006";
    QString type2 = "0002";
    QString type3 = "0000";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 风扇开
void maco::fso_Slot(){
    QString type = "0006";
    QString type2 = "0003";
    QString type3 = "0000";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 风扇关
void maco::fsc_Slot(){
    QString type = "0006";
    QString type2 = "0004";
    QString type3 = "0000";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 12;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+type3+type4+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 恢复初始 cnr
void maco::on_bot_bt1_clicked()
{
    QString column1Value,column2Value,column3Value,column4Value,column5Value,column6Value,
            column7Value,column8Value,column9Value,column10Value,column11Value,column12Value;
    if(true){
        QString type = "000D";
        QString type2 = "0001";
        QString type3;
        for(int i=1;i<=12;i++){
            QString sql="SELECT param_1,param_2,param_3,param_4,param_5,param_6,param_7,param_8 FROM Settings WHERE ID=%1";
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            query.exec(sql.arg(i));
            while (query.next()) {
                column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                column3Value = QString("%1").arg(query.value("param_3").toInt(), 4, 16, QLatin1Char('0'));
                column4Value = QString("%1").arg(query.value("param_4").toInt(), 4, 16, QLatin1Char('0'));
                column5Value = QString("%1").arg(query.value("param_5").toInt(), 4, 16, QLatin1Char('0'));
                column6Value = QString("%1").arg(query.value("param_6").toInt(), 4, 16, QLatin1Char('0'));
                column7Value = QString("%1").arg(query.value("param_7").toInt(), 4, 16, QLatin1Char('0'));
                column8Value = QString("%1").arg(query.value("param_8").toInt(), 4, 16, QLatin1Char('0'));
                type3+=column1Value+column2Value+column3Value+column4Value+column5Value+column6Value+column7Value+column8Value;
            }
            query.clear();
        }
        for(int i=13;i<=14;i++){
            QString sql="SELECT param_1,param_2,param_3,param_4,param_5,param_6 FROM Settings WHERE ID=%1";
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            query.exec(sql.arg(i));
            while (query.next()) {
                column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                column3Value = QString("%1").arg(query.value("param_3").toInt(), 4, 16, QLatin1Char('0'));
                column4Value = QString("%1").arg(query.value("param_4").toInt(), 4, 16, QLatin1Char('0'));
                column5Value = QString("%1").arg(query.value("param_5").toInt(), 4, 16, QLatin1Char('0'));
                column6Value = QString("%1").arg(query.value("param_6").toInt(), 4, 16, QLatin1Char('0'));
                type3+=column1Value+column2Value+column3Value+column4Value+column5Value+column6Value;
            }
            query.clear();
        }
        for(int i=0;i<2;i++){
            type3+="0000";
        }
        for(int i=15;i<=15;i++){
            QString sql="SELECT param_1,param_2 FROM Settings WHERE ID=%1";
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            query.exec(sql.arg(i));
            while (query.next()) {
                column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                type3+=column1Value+column2Value;
            }
            query.clear();
        }
        for(int i=16;i<=17;i++){
            QString sql="SELECT param_1,param_2,param_3,param_4,param_5,param_6,param_7,param_8,param_9,param_10 FROM Settings WHERE ID=%1";
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            query.exec(sql.arg(i));
            while (query.next()) {
                column1Value = QString("%1").arg(query.value("param_1").toInt(), 2, 16, QLatin1Char('0'));
                column2Value = QString("%1").arg(query.value("param_2").toInt(), 2, 16, QLatin1Char('0'));
                column3Value = QString("%1").arg(query.value("param_3").toInt(), 2, 16, QLatin1Char('0'));
                column4Value = QString("%1").arg(query.value("param_4").toInt(), 2, 16, QLatin1Char('0'));
                column5Value = QString("%1").arg(query.value("param_5").toInt(), 2, 16, QLatin1Char('0'));
                column6Value = QString("%1").arg(query.value("param_6").toInt(), 2, 16, QLatin1Char('0'));
                column7Value = QString("%1").arg(query.value("param_7").toInt(), 2, 16, QLatin1Char('0'));
                column8Value = QString("%1").arg(query.value("param_8").toInt(), 2, 16, QLatin1Char('0'));
                column9Value = QString("%1").arg(query.value("param_9").toInt(), 2, 16, QLatin1Char('0'));
                column10Value = QString("%1").arg(query.value("param_10").toInt(), 2, 16, QLatin1Char('0'));
                type3+=column1Value+column2Value+column3Value+column4Value+column5Value+column6Value+column7Value+column8Value+column9Value+column10Value;
            }
            query.clear();
        }
        for(int i=18;i<=18;i++){
            QString sql="SELECT param_1,param_2,param_3,param_4 FROM Settings WHERE ID=%1";
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            query.exec(sql.arg(i));
            while (query.next()) {
                column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                column3Value = QString("%1").arg(query.value("param_3").toInt(), 4, 16, QLatin1Char('0'));
                column4Value = QString("%1").arg(query.value("param_4").toInt(), 4, 16, QLatin1Char('0'));
                type3+=column1Value+column2Value+column3Value+column4Value;
            }
            query.clear();
        }
        for(int i=19;i<=19;i++){
            QString sql="SELECT param_1,param_2 FROM Settings WHERE ID=%1";
            QSqlDatabase db = dbHelper::openConnection();
            QSqlQuery query(db);
            query.exec(sql.arg(i));
            while (query.next()) {
                column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                type3+=column1Value+column2Value;
            }
            query.clear();
        }
        QString end2 = "0000";
        int len = 264;
        QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
        QString data = header+frame_Type4+len1+type+type2+type3+end2+end_frame;
        QString finalData;
        for (int i = 0; i < data.length(); ++i){
            finalData.append(data.at(i));
            // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
            if ((i+1)%2==0) {
                finalData.append(' ');
            }
        }
        QByteArray finalInfo=common->GetSendData(finalData);
        tcpClient->ClientSendingData(finalInfo);
        serialPortSend_Slot(finalInfo);
    }
    // 延迟0.2秒左右
    for(int i=0; i < 100000; i++)
    {
        //QCoreApplication::processEvents(QEventLoop::AllEvents);    //去处理本线程的事件循环，避免本线程被堵塞
        QCoreApplication::processEvents(QEventLoop::AllEvents, 5);//如果不够频繁，可以增加第二参数来缓解卡顿
    }
    if(true){
        QString column1Value,column2Value,column3Value,column4Value,column5Value,column6Value,
                column7Value,column8Value,column9Value,column10Value,column11Value,column12Value;
        if(true){
            QString type = "000D";
            QString type2 = "0002";
            QString type3;
            for(int i=20;i<=20;i++){
                QString sql="SELECT param_1,param_2,param_3,param_4 FROM Settings WHERE ID=%1";
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                query.exec(sql.arg(i));
                while (query.next()) {
                    column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                    column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                    column3Value = QString("%1").arg(query.value("param_3").toInt(), 4, 16, QLatin1Char('0'));
                    column4Value = QString("%1").arg(query.value("param_4").toInt(), 4, 16, QLatin1Char('0'));
                    type3+=column1Value+column2Value+column3Value+column4Value;
                }
                query.clear();
            }
            for(int i=21;i<=24;i++){
                QString sql="SELECT param_1,param_2,param_3,param_4,param_5,param_6,param_7,param_8 FROM Settings WHERE ID=%1";
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                query.exec(sql.arg(i));
                while (query.next()) {
                    column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                    column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                    column3Value = QString("%1").arg(query.value("param_3").toInt(), 4, 16, QLatin1Char('0'));
                    column4Value = QString("%1").arg(query.value("param_4").toInt(), 4, 16, QLatin1Char('0'));
                    column5Value = QString("%1").arg(query.value("param_5").toInt(), 4, 16, QLatin1Char('0'));
                    column6Value = QString("%1").arg(query.value("param_6").toInt(), 4, 16, QLatin1Char('0'));
                    column7Value = QString("%1").arg(query.value("param_7").toInt(), 4, 16, QLatin1Char('0'));
                    column8Value = QString("%1").arg(query.value("param_8").toInt(), 4, 16, QLatin1Char('0'));
                    type3+=column1Value+column2Value+column3Value+column4Value+column5Value+column6Value+column7Value+column8Value;
                }
                query.clear();
            }
            for(int i=25;i<=25;i++){
                QString sql="SELECT param_1,param_2,param_3,param_4,param_5,param_6,param_7,param_8,param_9,param_10,param_11,param_12 FROM Settings WHERE ID=%1";
                QSqlDatabase db = dbHelper::openConnection();
                QSqlQuery query(db);
                query.exec(sql.arg(i));
                while (query.next()) {
                    column1Value = QString("%1").arg(query.value("param_1").toInt(), 4, 16, QLatin1Char('0'));
                    column2Value = QString("%1").arg(query.value("param_2").toInt(), 4, 16, QLatin1Char('0'));
                    column3Value = QString("%1").arg(query.value("param_3").toInt(), 4, 16, QLatin1Char('0'));
                    column4Value = QString("%1").arg(query.value("param_4").toInt(), 4, 16, QLatin1Char('0'));
                    column5Value = QString("%1").arg(query.value("param_5").toInt(), 4, 16, QLatin1Char('0'));
                    column6Value = QString("%1").arg(query.value("param_6").toInt(), 4, 16, QLatin1Char('0'));
                    column7Value = QString("%1").arg(query.value("param_7").toInt(), 4, 16, QLatin1Char('0'));
                    column8Value = QString("%1").arg(query.value("param_8").toInt(), 4, 16, QLatin1Char('0'));
                    column9Value = QString("%1").arg(query.value("param_9").toInt(), 4, 16, QLatin1Char('0'));
                    column10Value = QString("%1").arg(query.value("param_10").toInt(), 4, 16, QLatin1Char('0'));
                    column11Value = QString("%1").arg(query.value("param_11").toInt(), 4, 16, QLatin1Char('0'));
                    column12Value = QString("%1").arg(query.value("param_12").toInt(), 4, 16, QLatin1Char('0'));
                    type3+=column1Value+column2Value+column3Value+column4Value+column5Value+column6Value+column7Value+column8Value+column9Value+column10Value+column11Value+column12Value;
                }
            }
            QString end2 = "0000";
            int len = 264;
            QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
            QString data = header+frame_Type4+len1+type+type2+type3+end2+end_frame;
            QString finalData;
            for (int i = 0; i < data.length(); ++i){
                finalData.append(data.at(i));
                // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
                if ((i+1)%2==0) {
                    finalData.append(' ');
                }
            }
            QByteArray finalInfo=common->GetSendData(finalData);
            tcpClient->ClientSendingData(finalInfo);
            serialPortSend_Slot(finalInfo);
        }
    }
    QMessageBox::information(this,"提示","恢复成功");
}

void maco::on_return_bt_clicked()
{
    qtwh1->close();
    this->close();
    emit changeMainWindow();
}

void maco::on_bot_bt2_2_clicked()
{
    QString type = "0000";
    QString type2 = "0001";
    QString type3 = "0005";
    QString type4 = QString("%1").arg(0, 4, 16, QLatin1Char('0'));
    QString end2 = "0000";
    int len = 10;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type2+len1+type+type2+type3+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}
// 检测偏差表格初始化 cnr 6.29
void maco::pctab(){
    ui->pc_tab->setRowCount(7);
    ui->pc_tab->setColumnCount(9);
    ui->pc_tab->setWindowTitle("QTableWidget & Item");
    ui->pc_tab->resizeColumnsToContents();
    ui->pc_tab->resizeRowsToContents();
    QStringList header;
    header<<"区域"<<"数据1"<<"数据2"<<"数据3"<<"数据4"<<"数据5"<<"最大值"<<"均值"<<"操作";
    ui->pc_tab->setHorizontalHeaderLabels(header);
    ui->pc_tab->verticalHeader()->setVisible(false);
    ui->pc_tab->setItem(0,0,new QTableWidgetItem("A"));
    ui->pc_tab->setItem(1,0,new QTableWidgetItem("B"));
    ui->pc_tab->setItem(2,0,new QTableWidgetItem("C"));
    ui->pc_tab->setItem(3,0,new QTableWidgetItem("D"));
    ui->pc_tab->setItem(4,0,new QTableWidgetItem("E"));
    ui->pc_tab->setItem(5,0,new QTableWidgetItem("F"));
    ui->pc_tab->setItem(6,0,new QTableWidgetItem("合计"));
    for(int i = 0 ;i < 7 ;i++){
        for(int j = 1;j < 9;j++){
            ui->pc_tab->setItem(i,j,new QTableWidgetItem(" "));
        }
    }
    for (int row = 0; row < ui->pc_tab->rowCount(); ++row) {
        for (int col = 0; col < ui->pc_tab->columnCount(); ++col){
            ui->pc_tab->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }

    for(int i=0;i<6;i++){
        QPushButton *btn_1 = new QPushButton();
        QPushButton *btn_2 = new QPushButton();
        btn_1->setText(tr("读取"));
        btn_2->setText(tr("设置"));
        btn_1->setMinimumSize(60,30);
        btn_2->setMinimumSize(60,30);
        QWidget *tmp_widget = new QWidget();
        QHBoxLayout *tmp_layout = new QHBoxLayout(tmp_widget);
        tmp_layout->addWidget(btn_1);
        tmp_layout->addWidget(btn_2);
        ui->pc_tab->setCellWidget(i,8,tmp_widget);
        connect(btn_1,SIGNAL(clicked()),this,SLOT(pcread_clicked()));
        connect(btn_2,SIGNAL(clicked()),this,SLOT(pcset_clicked()));
    }
    QPushButton *btn_2 = new QPushButton();
    btn_2->setText(tr("设置"));
    btn_2->setMinimumSize(60,30);
    QWidget *tmp_widget = new QWidget();
    QHBoxLayout *tmp_layout = new QHBoxLayout(tmp_widget);
    tmp_layout->addWidget(btn_2);
    ui->pc_tab->setCellWidget(6,8,tmp_widget);
    connect(btn_2,SIGNAL(clicked()),this,SLOT(pcset_clicked()));
    // 表头颜色
    ui->pc_tab->show();
    ui->pc_tab->blockSignals(false);
    QStringList kaw;
    kaw<<"A"<<"B"<<"C"<<"D"<<"E"<<"F";
    for(int i = 0;i<6;i++){
        QString sql="SELECT data_1,data_2,data_3,data_4,data_5,data_max,data_avg FROM Detbia WHERE td = :tdValue AND ka = :kaValue ;";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":tdValue", pcjztd);
        query.bindValue(":kaValue",kaw[i]);
        QStringList sanames;
        query.exec();
        while (query.next()){
            QString column1Value = query.value("data_1").toString();
            QString column2Value = query.value("data_2").toString();
            QString column3Value = query.value("data_3").toString();
            QString column4Value = query.value("data_4").toString();
            QString column5Value = query.value("data_5").toString();
            QString column6Value = query.value("data_max").toString();
            QString column7Value = query.value("data_avg").toString();
            sanames.append(column1Value);
            sanames.append(column2Value);
            sanames.append(column3Value);
            sanames.append(column4Value);
            sanames.append(column5Value);
            sanames.append(column6Value);
            sanames.append(column7Value);
        }
        for(int j=1;j<8;j++){
            ui->pc_tab->setItem(i,j,new QTableWidgetItem(sanames[j-1]));
        }
        query.clear();
    }
    QString sql="SELECT data_1,data_2,data_3,data_4,data_5,data_max,data_avg FROM Detbia WHERE td = :tdValue AND ka = :kaValue ;";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    query.prepare(sql);
    query.bindValue(":tdValue", pcjztd);
    query.bindValue(":kaValue","合计");
    QStringList sanames;
    query.exec();
    while (query.next()){
        QString column1Value = query.value("data_1").toString();
        QString column2Value = query.value("data_2").toString();
        QString column3Value = query.value("data_3").toString();
        QString column4Value = query.value("data_4").toString();
        QString column5Value = query.value("data_5").toString();
        QString column6Value = query.value("data_max").toString();
        QString column7Value = query.value("data_avg").toString();
        sanames.append(column1Value);
        sanames.append(column2Value);
        sanames.append(column3Value);
        sanames.append(column4Value);
        sanames.append(column5Value);
        sanames.append(column6Value);
        sanames.append(column7Value);
    }
    for(int j=1;j<8;j++){
        ui->pc_tab->setItem(6,j,new QTableWidgetItem(sanames[j-1]));
    }
    flpc=1;
}
// 维护校准A卡点击 cnr 7.1
void maco::on_A_bt_clicked()
{
    pcjzk = "A";
    ui->A_bt->setStyleSheet("background: #EBF3FF;border: 1px solid #2F42CD;");
    ui->B_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->C_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->D_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->E_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->F_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
}
// 维护校准b卡点击 cnr 7.1
void maco::on_B_bt_clicked()
{
    pcjzk = "B";
    ui->B_bt->setStyleSheet("background: #EBF3FF;border: 1px solid #2F42CD;");
    ui->A_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->C_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->D_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->E_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->F_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
}
// 维护校准C卡点击 cnr 7.1
void maco::on_C_bt_clicked()
{
    pcjzk = "C";
    ui->C_bt->setStyleSheet("background: #EBF3FF;border: 1px solid #2F42CD;");
    ui->B_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->A_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->D_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->E_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->F_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
}
// 维护校准D卡点击 cnr 7.1
void maco::on_D_bt_clicked()
{
    pcjzk = "D";
    ui->D_bt->setStyleSheet("background: #EBF3FF;border: 1px solid #2F42CD;");
    ui->B_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->C_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->A_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->E_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->F_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
}
// 维护校准E卡点击 cnr 7.1
void maco::on_E_bt_clicked()
{
    pcjzk = "E";
    ui->E_bt->setStyleSheet("background: #EBF3FF;border: 1px solid #2F42CD;");
    ui->B_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->C_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->D_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->A_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->F_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
}
// 维护校准F卡点击 cnr 7.1
void maco::on_F_bt_clicked()
{
    pcjzk = "F";
    ui->F_bt->setStyleSheet("background: #EBF3FF;border: 1px solid #2F42CD;");
    ui->B_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->C_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->D_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->E_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
    ui->A_bt->setStyleSheet("background: #FFFFFF;border: 1px solid #999999;");
}
// 维护校准读槽函数
void maco::pcread_clicked()
{
    pcadfl=1;
    on_ad1time_bt_clicked();
}
// 维护校准设置槽函数
void maco::pcset_clicked()
{
    QPushButton *btn = (QPushButton*)sender();
    QWidget *w_parent = (QWidget*)btn->parent();
    int x = w_parent->frameGeometry().x();
    int y = w_parent->frameGeometry().y();
    QModelIndex index = ui->pc_tab->indexAt(QPoint(x,y));
    if(index.row()<6){
        QString sql = "UPDATE Detbia SET "
                      "data_1 = :value1,"
                      "data_2 = :value2,"
                      "data_3 = :value3,"
                      "data_4 = :value4,"
                      "data_5 = :value5,"
                      "data_max = :valueMax,"
                      "data_avg = :valueAvg "
                      "WHERE td = :tdValue AND ka = :kaValue;";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":value1", ui->pc_tab->item(index.row(),1)->text());
        query.bindValue(":value2", ui->pc_tab->item(index.row(),2)->text());
        query.bindValue(":value3", ui->pc_tab->item(index.row(),3)->text());
        query.bindValue(":value4", ui->pc_tab->item(index.row(),4)->text());
        query.bindValue(":value5", ui->pc_tab->item(index.row(),5)->text());
        query.bindValue(":valueMax", ui->pc_tab->item(index.row(),6)->text());
        query.bindValue(":valueAvg", ui->pc_tab->item(index.row(),7)->text());
        query.bindValue(":tdValue", pcjztd);
        query.bindValue(":kaValue", pcjzk);
        query.exec();
    }else if(index.row()==6){
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        QString sql = "UPDATE Detbia SET "
                      "data_max = :valueMax, "
                      "data_avg = :valueAvg "
                      "WHERE td = :tdValue AND ka = :kaValue";
        query.prepare(sql);
        query.bindValue(":valueMax", ui->pc_tab->item(index.row(),6)->text());
        query.bindValue(":valueAvg", ui->pc_tab->item(index.row(),7)->text());
        query.bindValue(":tdValue", pcjztd);
        query.bindValue(":kaValue","合计");
        query.exec();
    }

}
// 维护校准通道改变
void maco::on_pc_cb_currentTextChanged(const QString &arg1)
{
    pcjztd=arg1;
    QStringList kaw;
    kaw<<"A"<<"B"<<"C"<<"D"<<"E"<<"F";
    for(int i = 0;i<6;i++){
        QString sql="SELECT data_1,data_2,data_3,data_4,data_5,data_max,data_avg FROM Detbia WHERE td = :tdValue AND ka = :kaValue ;";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":tdValue", pcjztd);
        query.bindValue(":kaValue",kaw[i]);
        QStringList sanames;
        query.exec();
        while (query.next()){
            QString column1Value = query.value("data_1").toString();
            QString column2Value = query.value("data_2").toString();
            QString column3Value = query.value("data_3").toString();
            QString column4Value = query.value("data_4").toString();
            QString column5Value = query.value("data_5").toString();
            QString column6Value = query.value("data_max").toString();
            QString column7Value = query.value("data_avg").toString();
            sanames.append(column1Value);
            sanames.append(column2Value);
            sanames.append(column3Value);
            sanames.append(column4Value);
            sanames.append(column5Value);
            sanames.append(column6Value);
            sanames.append(column7Value);
        }
        for(int j=1;j<8;j++){
            ui->pc_tab->setItem(i,j,new QTableWidgetItem(sanames[j-1]));
        }
        query.clear();
    }
    QString sql="SELECT data_1,data_2,data_3,data_4,data_5,data_max,data_avg FROM Detbia WHERE td = :tdValue AND ka = :kaValue ;";
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    query.prepare(sql);
    query.bindValue(":tdValue", pcjztd);
    query.bindValue(":kaValue","合计");
    QStringList sanames;
    query.exec();
    while (query.next()){
        QString column1Value = query.value("data_1").toString();
        QString column2Value = query.value("data_2").toString();
        QString column3Value = query.value("data_3").toString();
        QString column4Value = query.value("data_4").toString();
        QString column5Value = query.value("data_5").toString();
        QString column6Value = query.value("data_max").toString();
        QString column7Value = query.value("data_avg").toString();
        sanames.append(column1Value);
        sanames.append(column2Value);
        sanames.append(column3Value);
        sanames.append(column4Value);
        sanames.append(column5Value);
        sanames.append(column6Value);
        sanames.append(column7Value);
    }
    for(int j=1;j<8;j++){
        ui->pc_tab->setItem(6,j,new QTableWidgetItem(sanames[j-1]));
    }
    query.clear();
    numsum();
}
// 表格改变槽函数
void maco::on_pc_tab_cellChanged(int row, int column)
{

}
// 数据计算
void maco::numsum(){
    int row=pcmap.value(pcjzk);
    if(flpc==1){
        if(row<6){
            QList<int> yglist;
            for(int i=1 ; i<6 ; i++){
                yglist.append(ui->pc_tab->item(row,i)->text().toInt());
            }
            int maxVal=0;
            for(int j = 0; j < yglist.length() ;j++){
                int val1 = yglist[j];
                if(maxVal>val1){

                }else{
                    maxVal=val1;
                }
            }
            int avg=0;
            for(int j = 0; j < yglist.length() ;j++){
                avg+=yglist[j];
            }
            avg= avg / yglist.size();
            ui->pc_tab->setItem(row,6,new QTableWidgetItem(QString::number(maxVal)));
            ui->pc_tab->setItem(row,7,new QTableWidgetItem(QString::number(avg)));
        }
        int maxVal=0;
        int avg=0;
        for(int i=0;i<7;i++){
            maxVal+=ui->pc_tab->item(i,6)->text().toInt();
            avg+=ui->pc_tab->item(i,7)->text().toInt();
        }
        ui->pc_tab->setItem(6,6,new QTableWidgetItem(QString::number(maxVal)));
        ui->pc_tab->setItem(6,7,new QTableWidgetItem(QString::number(avg)));

    }
}
// 背景偏差表格功能实现 7.10
void maco::bjtab(){
    ui->bj_tab->setRowCount(8);
    ui->bj_tab->setColumnCount(49);
    ui->bj_tab->setWindowTitle("QTableWidget & Item");
    ui->bj_tab->resizeColumnsToContents();
    ui->bj_tab->resizeRowsToContents();
    QStringList header;
    header<<"卡位/通道"<<"1孔通道一"<<"1孔通道二"<<"1孔通道三"<<"1孔通道四"<<"2孔通道一"<<"2孔通道二"<<"2孔通道三"<<"2孔通道四"<<"3孔通道一"<<"3孔通道二"<<"3孔通道三"<<"3孔通道四"<<"4孔通道一"<<"4孔通道二"<<"4孔通道三"<<"4孔通道四"<<"5孔通道一"<<"5孔通道二"<<"5孔通道三"<<"5孔通道四"<<"6孔通道一"<<"6孔通道二"<<"6孔通道三"<<"6孔通道四"
         <<"7孔通道一"<<"7孔通道二"<<"7孔通道三"<<"7孔通道四"<<"8孔通道一"<<"8孔通道二"<<"8孔通道三"<<"8孔通道四"<<"9孔通道一"<<"9孔通道二"<<"9孔通道三"<<"9孔通道四"<<"10孔通道一"<<"10孔通道二"<<"10孔通道三"<<"10孔通道四"<<"11孔通道一"<<"11孔通道二"<<"11孔通道三"<<"11孔通道四"<<"12孔通道一"<<"12孔通道二"<<"12孔通道三"<<"12孔通道四";
    ui->bj_tab->setHorizontalHeaderLabels(header);
    ui->bj_tab->verticalHeader()->setVisible(false);
    ui->bj_tab->setItem(0,0,new QTableWidgetItem("A"));
    ui->bj_tab->setItem(1,0,new QTableWidgetItem("B"));
    ui->bj_tab->setItem(2,0,new QTableWidgetItem("C"));
    ui->bj_tab->setItem(3,0,new QTableWidgetItem("D"));
    ui->bj_tab->setItem(4,0,new QTableWidgetItem("E"));
    ui->bj_tab->setItem(5,0,new QTableWidgetItem("F"));
    ui->bj_tab->setItem(6,0,new QTableWidgetItem("G"));
    ui->bj_tab->setItem(7,0,new QTableWidgetItem("H"));
    for(int i = 0 ;i < 8 ;i++){
        for(int j = 1;j < 49;j++){
            ui->bj_tab->setItem(i,j,new QTableWidgetItem(" "));
        }
    }
    for (int row = 0; row < ui->bj_tab->rowCount(); ++row) {
        for (int col = 0; col < ui->bj_tab->columnCount(); ++col){
            ui->bj_tab->item (row,col)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        }
    }
    // 表头颜色
    ui->bj_tab->show();
    ui->bj_tab->blockSignals(false);
    QStringList kaw;
    kaw<<"A"<<"B"<<"C"<<"D"<<"E"<<"F"<<"G"<<"H";
    // 数据库查询
    for(int i = 0;i<8;i++){
        QString sql="SELECT * FROM Beijingpiancha WHERE ka = :kaValue ;";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":kaValue",kaw[i]);
        QStringList columnNames = {
            "FAM1k", "VIC1k", "ROX1k", "CY51k",
            "FAM2k", "VIC2k", "ROX2k", "CY52k",
            "FAM3k", "VIC3k", "ROX3k", "CY53k",
            "FAM4k", "VIC4k", "ROX4k", "CY54k",
            "FAM5k", "VIC5k", "ROX5k", "CY55k",
            "FAM6k", "VIC6k", "ROX6k", "CY56k",
            "FAM7k", "VIC7k", "ROX7k", "CY57k",
            "FAM8k", "VIC8k", "ROX8k", "CY58k",
            "FAM9k", "VIC9k", "ROX9k", "CY59k",
            "FAM10k", "VIC10k", "ROX10k", "CY510k",
            "FAM11k", "VIC11k", "ROX11k", "CY511k",
            "FAM12k", "VIC12k", "ROX12k", "CY512k"
        };

        QStringList sanames;
        query.exec();
        while (query.next()) {
            for (const QString &columnName : columnNames) {
                QString value = query.value(columnName).toString();
                sanames.append(value);
            }
        }
        for(int j=1;j<49;j++){
            ui->bj_tab->setItem(i,j,new QTableWidgetItem(sanames[j-1]));
        }
        query.clear();
    }
}
// 背景偏差保存
void maco::on_bjbc_bt_clicked()
{
    for(int i=0;i<8;i++){
        QString sql = "UPDATE Beijingpiancha SET "
                      "ka = :value1,"
                      "FAM1k = :value2,"
                      "VIC1k = :value3,"
                      "ROX1k = :value4,"
                      "CY51k = :value5,"
                      "FAM2k = :value6,"
                      "VIC2k = :value7,"
                      "ROX2k = :value8,"
                      "CY52k = :value9,"
                      "FAM3k = :value10,"
                      "VIC3k = :value11,"
                      "ROX3k = :value12,"
                      "CY53k = :value13,"
                      "FAM4k = :value14,"
                      "VIC4k = :value15,"
                      "ROX4k = :value16,"
                      "CY54k = :value17,"
                      "FAM5k = :value18,"
                      "VIC5k = :value19,"
                      "ROX5k = :value20,"
                      "CY55k = :value21,"
                      "FAM6k = :value22,"
                      "VIC6k = :value23,"
                      "ROX6k = :value24,"
                      "CY56k = :value25,"
                      "FAM7k = :value26,"
                      "VIC7k = :value27,"
                      "ROX7k = :value28,"
                      "CY57k = :value29,"
                      "FAM8k = :value30,"
                      "VIC8k = :value31,"
                      "ROX8k = :value32,"
                      "CY58k = :value33,"
                      "FAM9k = :value34,"
                      "VIC9k = :value35,"
                      "ROX9k = :value36,"
                      "CY59k = :value37,"
                      "FAM10k = :value38,"
                      "VIC10k = :value39,"
                      "ROX10k = :value40,"
                      "CY510k = :value41,"
                      "FAM11k = :value42,"
                      "VIC11k = :value43,"
                      "ROX11k = :value44,"
                      "CY511k = :value45,"
                      "FAM12k = :value46,"
                      "VIC12k = :value47,"
                      "ROX12k = :value48,"
                      "CY512k = :value49 "
                      "WHERE ka = :kaValue;";
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        query.prepare(sql);
        query.bindValue(":value1", ui->bj_tab->item(i,0)->text());
        query.bindValue(":value2", ui->bj_tab->item(i,1)->text());
        query.bindValue(":value3", ui->bj_tab->item(i,2)->text());
        query.bindValue(":value4", ui->bj_tab->item(i,3)->text());
        query.bindValue(":value5", ui->bj_tab->item(i,4)->text());
        query.bindValue(":value6", ui->bj_tab->item(i,5)->text());
        query.bindValue(":value7", ui->bj_tab->item(i,6)->text());
        query.bindValue(":value8", ui->bj_tab->item(i,7)->text());
        query.bindValue(":value9", ui->bj_tab->item(i,8)->text());
        query.bindValue(":value10", ui->bj_tab->item(i,9)->text());
        query.bindValue(":value11", ui->bj_tab->item(i,10)->text());
        query.bindValue(":value12", ui->bj_tab->item(i,11)->text());
        query.bindValue(":value13", ui->bj_tab->item(i,12)->text());
        query.bindValue(":value14", ui->bj_tab->item(i,13)->text());
        query.bindValue(":value15", ui->bj_tab->item(i,14)->text());
        query.bindValue(":value16", ui->bj_tab->item(i,15)->text());
        query.bindValue(":value17", ui->bj_tab->item(i,16)->text());
        query.bindValue(":value18", ui->bj_tab->item(i,17)->text());
        query.bindValue(":value19", ui->bj_tab->item(i,18)->text());
        query.bindValue(":value20", ui->bj_tab->item(i,19)->text());
        query.bindValue(":value21", ui->bj_tab->item(i,20)->text());
        query.bindValue(":value22", ui->bj_tab->item(i,21)->text());
        query.bindValue(":value23", ui->bj_tab->item(i,22)->text());
        query.bindValue(":value24", ui->bj_tab->item(i,23)->text());
        query.bindValue(":value25", ui->bj_tab->item(i,24)->text());
        query.bindValue(":value26", ui->bj_tab->item(i,25)->text());
        query.bindValue(":value27", ui->bj_tab->item(i,26)->text());
        query.bindValue(":value28", ui->bj_tab->item(i,27)->text());
        query.bindValue(":value29", ui->bj_tab->item(i,28)->text());
        query.bindValue(":value30", ui->bj_tab->item(i,29)->text());
        query.bindValue(":value31", ui->bj_tab->item(i,30)->text());
        query.bindValue(":value32", ui->bj_tab->item(i,31)->text());
        query.bindValue(":value33", ui->bj_tab->item(i,32)->text());
        query.bindValue(":value34", ui->bj_tab->item(i,33)->text());
        query.bindValue(":value35", ui->bj_tab->item(i,34)->text());
        query.bindValue(":value36", ui->bj_tab->item(i,35)->text());
        query.bindValue(":value37", ui->bj_tab->item(i,36)->text());
        query.bindValue(":value38", ui->bj_tab->item(i,37)->text());
        query.bindValue(":value39", ui->bj_tab->item(i,38)->text());
        query.bindValue(":value40", ui->bj_tab->item(i,39)->text());
        query.bindValue(":value41", ui->bj_tab->item(i,40)->text());
        query.bindValue(":value42", ui->bj_tab->item(i,41)->text());
        query.bindValue(":value43", ui->bj_tab->item(i,42)->text());
        query.bindValue(":value44", ui->bj_tab->item(i,43)->text());
        query.bindValue(":value45", ui->bj_tab->item(i,44)->text());
        query.bindValue(":value46", ui->bj_tab->item(i,45)->text());
        query.bindValue(":value47", ui->bj_tab->item(i,46)->text());
        query.bindValue(":value48", ui->bj_tab->item(i,47)->text());
        query.bindValue(":value49", ui->bj_tab->item(i,48)->text());
        query.bindValue(":kaValue", ui->bj_tab->item(i,0)->text());
        query.exec();
    }
    QString type = "000A000A";
    QString type2 = "0002";
    QString ty;
    ty.append(type);
    ty.append(type2);
    for(int i=0;i<8;i++){
        for(int j=1;j<49;j++){
            int datava;
            datava = ui->bj_tab->item(i,j)->text().toInt();
            ty.append(QString("%1").arg(datava, 4, 16, QLatin1Char('0')));
        }
    }
    QString end2 = "0000";
    int len = 778;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+ty+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
    QMessageBox::information(NULL, "提示", "表格保存成功");
}
// 背景偏差导入
void maco::on_bjdr_bt_clicked()
{
    //    QString desktopDir=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
    //    QString path=QFileDialog::getOpenFileName(NULL,"选择Excel",desktopDir,"*.xlsx *.xls");
    //    if(path==NULL){
    //        return;
    //    }
    //    QAxObject *excel = NULL;
    //    QAxObject *workbooks = NULL;
    //    QAxObject *workbook = NULL;
    //    excel = new QAxObject(this);
    //    if (!excel->setControl("Excel.Application"))
    //    {
    //        excel->setControl("ket.Application");
    //    }
    //    if (!excel)
    //    {
    //        QMessageBox::critical(NULL, "错误信息", "EXCEL对象丢失");
    //        return;
    //    }
    //    excel->dynamicCall("SetVisible(bool)", false);
    //    workbooks = excel->querySubObject("WorkBooks");
    //    workbook = workbooks->querySubObject("Open(const QString&)",path);
    //    QAxObject * worksheet = workbook->querySubObject("WorkSheets(int)", 1); // 获取第一个工作sheet
    //    QAxObject * usedrange = worksheet->querySubObject("UsedRange");//获取该sheet的使用范围对象
    //    QAxObject * rows = usedrange->querySubObject("Rows");
    //    QAxObject * columns = usedrange->querySubObject("Columns");

    //    /*获取行数和列数*/
    //    int intCols = columns->property("Count").toInt();
    //    int intRows = rows->property("Count").toInt();

    //    /*获取excel内容*/
    //    for (int i = 1; i <  intRows+1; i++)  //行
    //    {
    //        for (int j = 2; j <  intCols+1; j++)
    //        {
    //            QAxObject *cell = worksheet->querySubObject("Cells(int,int)", i, j);
    //            QTableWidgetItem *item = new QTableWidgetItem(QString::number(cell->dynamicCall("Value2()").toDouble(), 'f', 2));
    //            ui->bj_tab->setItem(i-2, j-1, item);
    //            delete cell;
    //        }
    //    }
    //    // 关闭excel
    //    workbook->dynamicCall("Close(Boolean)",true);
    //    excel->dynamicCall("Quit(void)");
    //    delete excel;
    //    excel = NULL;
    //    QMessageBox::information(NULL, "表格导入提示", "表格导入成功");
}
// 背景偏差导出
void maco::on_bjdc_bt_clicked()
{
    //    QString fileName = QFileDialog::getSaveFileName(this, tr("保存"), "", tr("Excel 文件(*.xlsx)"));
    //    if(fileName != ""){
    //        QAxObject *excel = new QAxObject;
    //        if(excel->setControl("Excel.Application")){
    //            excel->dynamicCall("SetVisible (bool Visible)","false");//不显示窗体
    //            excel->setProperty("DisplayAlerts", false);//不显示任何警告信息。如果为true那么在关闭是会出现类似“文件已修改，是否保存”的提示
    //            QAxObject *workbooks = excel->querySubObject("WorkBooks");//获取工作簿集合
    //            workbooks->dynamicCall("Add");//新建一个工作簿
    //            QAxObject *workbook = excel->querySubObject("ActiveWorkBook");//获取当前工作簿
    //            QAxObject *sheets = workbook->querySubObject("Worksheets");
    //            if(true){
    //                QAxObject *worksheet = workbook->querySubObject("Worksheets(int)", 1);
    //                worksheet->setProperty("Name", "荧光表格");
    //                //调整行高
    //                worksheet->querySubObject("Range(const QString&)", "1:1")->setProperty("RowHeight", 30);
    //                //数据区
    //                // 写入表头
    //                int columnCount = ui->bj_tab->columnCount();
    //                for (int j = 0; j < columnCount; ++j) {
    //                    QAxObject *cell = worksheet->querySubObject("Cells(int,int)", 1, j + 1);
    //                    cell->dynamicCall("SetValue(const QVariant&)", ui->bj_tab->horizontalHeaderItem(j)->text());
    //                }

    //                // 写入表内容
    //                int rowCount = ui->bj_tab->rowCount();
    //                for (int i = 0; i < rowCount; ++i) {
    //                    for (int j = 0; j < columnCount; ++j) {
    //                        QTableWidgetItem *item = ui->bj_tab->item(i, j);
    //                        if (item) {
    //                            QAxObject *cell = worksheet->querySubObject("Cells(int,int)", i + 2, j + 1);
    //                            cell->dynamicCall("SetValue(const QVariant&)", item->text());
    //                        }
    //                    }
    //                }
    //            }
    //            workbook->dynamicCall("SaveAs(const QString&)", QDir::toNativeSeparators(fileName));//保存至fileName
    //            workbook->dynamicCall("Close()");//关闭工作簿
    //            excel->dynamicCall("Quit()");//关闭excel
    //            delete excel;
    //            excel = nullptr;
    //            QMessageBox::information(NULL, "表格导出提示", "表格导出成功");
    //        }
    //    }
}
// 背景偏差读取
void maco::on_bjdqbt_clicked()
{
    QString type = "000A000A";
    QString type2 = "0001";
    QString ty;
    ty.append(type);
    ty.append(type2);
    QString end2 = "0000";
    int len = 10;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+ty+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i){
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}

void maco::on_open_bt_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
        ui->open_bt->setText("        关闭仓门");
    }
    else
    {
        doorStatus.set(0);
        ui->open_bt->setText("        打开仓门");
    }
}

void maco::showEvent(QShowEvent *event)
{
    tcpClient = TcpClient::getInstance();
    if(doorStatus.get()==0)
    {
        ui->open_bt->setText("        打开仓门");
    }
    else
    {
        ui->open_bt->setText("        关闭仓门");
    }
    ui->top_bt1->click();
    event->accept();
}
// 光强系数读取
void maco::on_gqr_bt_2_clicked()
{
    QString type = "0004";
    QString type2 = "0001";
    QString ty;
    ty.append(type);
    ty.append(type2);
    QString end2 = "0000";
    int len = 8;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+ty+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i){
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
}
// 光强系数写入
void maco::on_gqw_bt_2_clicked()
{
    QString type = "0004";
    QString type2 = "0002";
    QString ty;
    ty.append(type);
    ty.append(type2);
    int xss1=ui->lineEdit->text().toDouble()*100;
    int xss2=ui->lineEdit_2->text().toDouble()*100;
    int xss3=ui->lineEdit_3->text().toDouble()*100;
    int xss4=ui->lineEdit_4->text().toDouble()*100;
    int xss5=ui->lineEdit_6->text().toDouble()*100;
    int xss6=ui->lineEdit_8->text().toDouble()*100;
    int xss7=ui->lineEdit_5->text().toDouble()*100;
    int xss8=ui->lineEdit_7->text().toDouble()*100;
    QString xs1 = QString("%1").arg(xss1, 4, 16, QLatin1Char('0'));
    QString xs2 = QString("%1").arg(xss2, 4, 16, QLatin1Char('0'));
    QString xs3 = QString("%1").arg(xss3, 4, 16, QLatin1Char('0'));
    QString xs4 = QString("%1").arg(xss4, 4, 16, QLatin1Char('0'));
    QString xs5 = QString("%1").arg(xss5, 4, 16, QLatin1Char('0'));
    QString xs6 = QString("%1").arg(xss6, 4, 16, QLatin1Char('0'));
    QString xs7 = QString("%1").arg(xss7, 4, 16, QLatin1Char('0'));
    QString xs8 = QString("%1").arg(xss8, 4, 16, QLatin1Char('0'));
    ty.append(xs1);
    ty.append(xs2);
    ty.append(xs3);
    ty.append(xs4);
    ty.append(xs5);
    ty.append(xs6);
    ty.append(xs7);
    ty.append(xs8);
    QString end2 = "0000";
    int len = 24;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type3+len1+ty+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i){
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
}

void maco::on_djss_bt_2_clicked()
{
    QString type = "000F";
    QString type2 = "0001";
    QString wen2 = "0000";
    QString end2 = "0000";
    int len = 10;
    QString len1 = QString("%1").arg(len, 4, 16, QLatin1Char('0'));
    QString data = header+frame_Type4+len1+type+type2+wen2+end2+end_frame;
    QString finalData;
    for (int i = 0; i < data.length(); ++i) {
        finalData.append(data.at(i));
        // 如果不是字符串的最后一个字符，并且i是偶数（从0开始），则添加一个空格
        if ((i+1)%2==0) {
            finalData.append(' ');
        }
    }
    QByteArray finalInfo=common->GetSendData(finalData);
    tcpClient->ClientSendingData(finalInfo);
    serialPortSend_Slot(finalInfo);
}

